Skip to content

Commit 3dd5407

Browse files
committed
Separate conventional processing into function
1 parent 093842d commit 3dd5407

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,35 @@ internal class KotlinNamesAnnotationIntrospector(
3333
val ignoredClassesForImplyingJsonCreator: Set<KClass<*>>,
3434
val useKotlinPropertyNameForGetter: Boolean
3535
) : NopAnnotationIntrospector() {
36+
private fun getterNameFromJava(member: AnnotatedMember): String? {
37+
val name = member.name
38+
39+
// The reason for truncating after `-` is to truncate the random suffix
40+
// given after the value class accessor name.
41+
return when {
42+
name.startsWith("get") -> name.takeIf { it.contains("-") }?.let { _ ->
43+
name.substringAfter("get")
44+
.replaceFirstChar { it.lowercase(Locale.getDefault()) }
45+
.substringBefore('-')
46+
}
47+
// since 2.15: support Kotlin's way of handling "isXxx" backed properties where
48+
// logical property name needs to remain "isXxx" and not become "xxx" as with Java Beans
49+
// (see https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html and
50+
// https://github.com/FasterXML/jackson-databind/issues/2527 and
51+
// https://github.com/FasterXML/jackson-module-kotlin/issues/340
52+
// for details)
53+
name.startsWith("is") -> if (name.contains("-")) name.substringAfter("-") else name
54+
else -> null
55+
}
56+
}
57+
3658
// since 2.4
3759
override fun findImplicitPropertyName(member: AnnotatedMember): String? {
3860
if (!member.declaringClass.isKotlinClass()) return null
3961

40-
val name = member.name
41-
4262
return when (member) {
4363
is AnnotatedMethod -> if (member.parameterCount == 0) {
44-
// The reason for truncating after `-` is to truncate the random suffix
45-
// given after the value class accessor name.
46-
when {
47-
name.startsWith("get") -> name.takeIf { it.contains("-") }?.let { _ ->
48-
name.substringAfter("get")
49-
.replaceFirstChar { it.lowercase(Locale.getDefault()) }
50-
.substringBefore('-')
51-
}
52-
// since 2.15: support Kotlin's way of handling "isXxx" backed properties where
53-
// logical property name needs to remain "isXxx" and not become "xxx" as with Java Beans
54-
// (see https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html and
55-
// https://github.com/FasterXML/jackson-databind/issues/2527 and
56-
// https://github.com/FasterXML/jackson-module-kotlin/issues/340
57-
// for details)
58-
name.startsWith("is") -> if (name.contains("-")) name.substringAfter("-") else name
59-
else -> null
60-
}
64+
if (useKotlinPropertyNameForGetter) TODO() else getterNameFromJava(member)
6165
} else null
6266
is AnnotatedParameter -> findKotlinParameterName(member)
6367
else -> null

0 commit comments

Comments
 (0)