Skip to content

Commit 733b056

Browse files
authored
Merge pull request #447 from k163377/fix_findsubtypes
Fix `KotlinAnnotationIntrospector.findSubtypes` returning wrong value in super edge case.
2 parents d29e80c + ebf3af4 commit 733b056

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,15 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
6363
* Subclasses can be detected automatically for sealed classes, since all possible subclasses are known
6464
* at compile-time to Kotlin. This makes [com.fasterxml.jackson.annotation.JsonSubTypes] redundant.
6565
*/
66-
override fun findSubtypes(a: Annotated): MutableList<NamedType>? {
67-
68-
val rawType = a.rawType
69-
if (rawType.isKotlinClass()) {
70-
val kClass = rawType.kotlin
71-
if (kClass.isSealed) {
72-
return kClass.sealedSubclasses
73-
.map { NamedType(it.java) }
74-
.toMutableList()
75-
}
66+
override fun findSubtypes(a: Annotated): MutableList<NamedType>? = a.rawType
67+
.takeIf { it.isKotlinClass() }
68+
?.let { rawType ->
69+
rawType.kotlin.sealedSubclasses
70+
.map { NamedType(it.java) }
71+
.toMutableList()
72+
.ifEmpty { null }
7673
}
7774

78-
return null
79-
80-
}
81-
8275
private fun AnnotatedField.hasRequiredMarker(): Boolean? {
8376
val byAnnotation = (member as Field).isRequiredByAnnotation()
8477
val byNullability = (member as Field).kotlinProperty?.returnType?.isRequired()

0 commit comments

Comments
 (0)