@@ -2,7 +2,10 @@ package com.fasterxml.jackson.module.kotlin
2
2
3
3
import com.fasterxml.jackson.annotation.JsonCreator
4
4
import com.fasterxml.jackson.annotation.JsonProperty
5
+ import com.fasterxml.jackson.databind.PropertyName
6
+ import com.fasterxml.jackson.databind.cfg.MapperConfig
5
7
import com.fasterxml.jackson.databind.introspect.*
8
+ import com.fasterxml.jackson.databind.util.BeanUtil
6
9
import java.lang.reflect.Constructor
7
10
import java.lang.reflect.Method
8
11
import kotlin.reflect.KClass
@@ -16,7 +19,6 @@ import kotlin.reflect.jvm.internal.KotlinReflectionInternalError
16
19
import kotlin.reflect.jvm.javaType
17
20
import kotlin.reflect.jvm.kotlinFunction
18
21
19
-
20
22
internal class KotlinNamesAnnotationIntrospector (val module : KotlinModule , val cache : ReflectionCache , val ignoredClassesForImplyingJsonCreator : Set <KClass <* >>) : NopAnnotationIntrospector() {
21
23
/*
22
24
override public fun findNameForDeserialization(annotated: Annotated?): PropertyName? {
@@ -29,14 +31,22 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
29
31
override fun findImplicitPropertyName (member : AnnotatedMember ): String? {
30
32
if (member is AnnotatedParameter ) {
31
33
return findKotlinParameterName(member)
32
- } else if (member is AnnotatedMethod ) {
33
- // 25-Oct-2019: [module-kotlin#80] Match "isGetter" with field with same name
34
- // since Kotlin generates accessor different from Java
35
- if (member.declaringClass.isKotlinClass()) {
36
- if (cache.isKotlinGeneratedMethod(member) { it.declaringClass.declaredFields.any {
37
- f -> f.name.startsWith(" is" ) && f.name == member.name } }) {
38
- return member.name
39
- }
34
+ }
35
+ return null
36
+ }
37
+
38
+ // since 2.11: support Kotlin's way of handling "isXxx" backed properties where
39
+ // logical property name needs to remain "isXxx" and not become "xxx" as with Java Beans
40
+ // (see https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html and
41
+ // https://github.com/FasterXML/jackson-databind/issues/2527
42
+ // for details)
43
+ override fun findRenameByField (config : MapperConfig <* >,
44
+ field : AnnotatedField , implName : PropertyName ): PropertyName ? {
45
+ val origSimple = implName.simpleName
46
+ if (field.declaringClass.isKotlinClass() && origSimple.startsWith(" is" )) {
47
+ val mangledName: String? = BeanUtil .stdManglePropertyName(origSimple, 2 )
48
+ if ((mangledName != null ) && ! mangledName.equals(origSimple)) {
49
+ return PropertyName .construct(mangledName)
40
50
}
41
51
}
42
52
return null
@@ -48,10 +58,10 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
48
58
49
59
if (member is AnnotatedConstructor && ! member.declaringClass.isEnum) {
50
60
// if has parameters, is a Kotlin class, and the parameters all have parameter annotations, then pretend we have a JsonCreator
51
- if (member.getParameterCount() > 0 && member.getDeclaringClass() .isKotlinClass()) {
61
+ if (member.getParameterCount() > 0 && member.declaringClass .isKotlinClass()) {
52
62
return cache.checkConstructorIsCreatorAnnotated(member) {
53
- val kClass = cache.kotlinFromJava(member.getDeclaringClass() as Class <Any >)
54
- val kConstructor = cache.kotlinFromJava(member.getAnnotated() as Constructor <Any >)
63
+ val kClass = cache.kotlinFromJava(member.declaringClass as Class <Any >)
64
+ val kConstructor = cache.kotlinFromJava(member.annotated as Constructor <Any >)
55
65
56
66
if (kConstructor != null ) {
57
67
val isPrimaryConstructor = kClass.primaryConstructor == kConstructor ||
@@ -107,7 +117,7 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
107
117
108
118
@Suppress(" UNCHECKED_CAST" )
109
119
protected fun findKotlinParameterName (param : AnnotatedParameter ): String? {
110
- if (param.getDeclaringClass() .isKotlinClass()) {
120
+ if (param.declaringClass .isKotlinClass()) {
111
121
val member = param.getOwner().getMember()
112
122
val name = if (member is Constructor <* >) {
113
123
val ctor = (member as Constructor <Any >)
0 commit comments