add unbox key serializer
ADD
src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinKeySerializers.kt
+package com.fasterxml.jackson.module.kotlin
+
+import com.fasterxml.jackson.core.JsonGenerator
+import com.fasterxml.jackson.databind.*
+import com.fasterxml.jackson.databind.ser.Serializers
+import com.fasterxml.jackson.databind.ser.std.StdSerializer
+import com.fasterxml.jackson.databind.type.TypeFactory
+
+internal object ValueClassUnboxKeySerializer : StdSerializer<Any>(Any::class.java) {
+ override fun serialize(value: Any, gen: JsonGenerator, provider: SerializerProvider) {
+ val method = value::class.java.getMethod("unbox-impl")
+ val unboxed = method.invoke(value)
+
+ if (unboxed == null) {
+ val javaType = provider.typeFactory.constructType(method.genericReturnType)
+ provider.findNullKeySerializer(javaType, null).serialize(null, gen, provider)
+ return
+ }
+
+ provider.findKeySerializer(unboxed::class.java, null).serialize(unboxed, gen, provider)
+ }
+}
+
+class KotlinKeySerializers : Serializers.Base() {
+ override fun findSerializer(
+ config: SerializationConfig,
+ type: JavaType,
+ beanDesc: BeanDescription
+ ): JsonSerializer<*>? = when {
+ type.rawClass.isUnboxableValueClass() -> ValueClassUnboxKeySerializer
+ else -> null
+ }
+}

MODIFY
src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt
src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt
@@ -123,6 +123,7 @@ class KotlinModule @Deprecated(
context.addDeserializers(KotlinDeserializers())
context.addSerializers(KotlinSerializers())
+ context.addKeySerializers(KotlinKeySerializers())
fun addMixIn(clazz: Class<*>, mixin: Class<*>) {
context.setMixInAnnotations(clazz, mixin)

add unbox key serializer