Skip to content

Commit 22e1936

Browse files
committed
Modified to serialize only properties on Kotlin
1 parent 3e8055f commit 22e1936

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
4242
else -> null
4343
}
4444

45+
// If it is not a property on Kotlin, it is not used to serialization
46+
override fun findPropertyAccess(ann: Annotated): JsonProperty.Access? = when (ann) {
47+
is AnnotatedMethod ->
48+
ann.annotated
49+
.takeIf { it.parameters.isEmpty() } // Ignore target is only getter
50+
?.let { method ->
51+
method.declaringClass.toKmClass()?.let { kmClass ->
52+
val methodSignature = method.toSignature()
53+
54+
JsonProperty.Access.WRITE_ONLY.takeIf {
55+
kmClass.properties.none { it.getterSignature == methodSignature }
56+
}
57+
}
58+
}
59+
else -> null
60+
}
61+
4562
@Suppress("UNCHECKED_CAST")
4663
private fun hasCreatorAnnotation(member: AnnotatedConstructor): Boolean {
4764
// don't add a JsonCreator to any constructor if one is declared already

0 commit comments

Comments
 (0)