Skip to content

Commit 1660b94

Browse files
committed
fix generics
1 parent eb38c62 commit 1660b94

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinAnnotationIntrospector.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
6262
}
6363

6464
// Find a serializer to handle the case where the getter returns an unboxed value from the value class.
65-
override fun findSerializer(am: Annotated): ValueClassBoxSerializer? = when (am) {
65+
override fun findSerializer(am: Annotated): ValueClassBoxSerializer<*>? = when (am) {
6666
is AnnotatedMethod -> {
6767
val getter = am.member.apply {
6868
// If the return value of the getter is a value class,
@@ -85,9 +85,10 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
8585

8686
(kotlinProperty?.returnType?.classifier as? KClass<*>)
8787
?.takeIf { it.isValue }
88+
?.java
8889
?.let { outerClazz ->
8990
@Suppress("UNCHECKED_CAST")
90-
ValueClassBoxSerializer(outerClazz as KClass<Any>, getter.returnType)
91+
ValueClassBoxSerializer(outerClazz, getter.returnType)
9192
}
9293
}
9394
// Ignore the case of AnnotatedField, because JvmField cannot be set in the field of value class.

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinSerializers.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ internal class KotlinSerializers : Serializers.Base() {
7777
// The getter generated for the value class is special,
7878
// so this class will not work properly when added to the Serializers
7979
// (it is configured from KotlinAnnotationIntrospector.findSerializer).
80-
internal class ValueClassBoxSerializer(
81-
outerClazz: KClass<Any>, innerClazz: Class<*>
82-
) : StdSerializer<Any>(outerClazz.java) {
83-
private val boxMethod = _handledType.getMethod("box-impl", innerClazz)
80+
internal class ValueClassBoxSerializer<T : Any>(
81+
private val outerClazz: Class<out Any>, innerClazz: Class<T>
82+
) : StdSerializer<T>(innerClazz) {
83+
private val boxMethod = outerClazz.getMethod("box-impl", innerClazz)
8484

85-
override fun serialize(value: Any?, gen: JsonGenerator, provider: SerializerProvider) {
85+
override fun serialize(value: T?, gen: JsonGenerator, provider: SerializerProvider) {
8686
// Values retrieved from getter are considered validated and constructor-impl is not executed.
8787
val boxed = boxMethod.invoke(null, value)
8888

89-
provider.findValueSerializer(_handledType).serialize(boxed, gen, provider)
89+
provider.findValueSerializer(outerClazz).serialize(boxed, gen, provider)
9090
}
9191
}

0 commit comments

Comments
 (0)