Skip to content

Commit 0586949

Browse files
authored
Merge pull request #727 from k163377/find-creator
Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation
2 parents 69f3e22 + 23e8185 commit 0586949

File tree

4 files changed

+12
-17
lines changed

4 files changed

+12
-17
lines changed

release-notes/CREDITS-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Authors:
1616
Contributors:
1717

1818
# 2.17.0 (not yet released)
19+
* #727: Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation
1920

2021
# 2.16.0
2122

release-notes/VERSION-2.x

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Co-maintainers:
1818

1919
2.17.0 (not yet released)
2020

21-
-
21+
#727: Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation.
2222

2323
2.16.0 (15-Nov-2023)
2424

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

-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.fasterxml.jackson.module.kotlin
22

3-
import com.fasterxml.jackson.annotation.JsonCreator
43
import com.fasterxml.jackson.annotation.JsonProperty
54
import com.fasterxml.jackson.databind.DeserializationFeature
65
import com.fasterxml.jackson.databind.JsonSerializer
76
import com.fasterxml.jackson.databind.Module
8-
import com.fasterxml.jackson.databind.cfg.MapperConfig
97
import com.fasterxml.jackson.databind.introspect.*
108
import com.fasterxml.jackson.databind.jsontype.NamedType
119
import com.fasterxml.jackson.databind.util.Converter
@@ -59,15 +57,6 @@ internal class KotlinAnnotationIntrospector(
5957
return hasRequired
6058
}
6159

62-
override fun findCreatorAnnotation(config: MapperConfig<*>, a: Annotated): JsonCreator.Mode? {
63-
64-
// TODO: possible work around for JsonValue class that requires the class constructor to have the JsonCreator(Mode.DELEGATED) set?
65-
// since we infer the creator at times for these methods, the wrong mode could be implied.
66-
67-
// findCreatorBinding used to be a clearer way to set this, but we need to set the mode here to disambugiate the intent of the constructor
68-
return super.findCreatorAnnotation(config, a)
69-
}
70-
7160
override fun findSerializationConverter(a: Annotated): Converter<*, *>? = when (a) {
7261
// Find a converter to handle the case where the getter returns an unboxed value from the value class.
7362
is AnnotatedMethod -> a.findValueClassReturnType()?.let {

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.fasterxml.jackson.module.kotlin
22

33
import com.fasterxml.jackson.annotation.JsonCreator
44
import com.fasterxml.jackson.annotation.JsonProperty
5+
import com.fasterxml.jackson.databind.cfg.MapperConfig
56
import com.fasterxml.jackson.databind.introspect.Annotated
67
import com.fasterxml.jackson.databind.introspect.AnnotatedConstructor
78
import com.fasterxml.jackson.databind.introspect.AnnotatedMember
@@ -111,11 +112,15 @@ internal class KotlinNamesAnnotationIntrospector(
111112
}
112113
}
113114

114-
override fun hasCreatorAnnotation(member: Annotated): Boolean =
115-
if (member is AnnotatedConstructor && member.isKotlinConstructorWithParameters())
116-
cache.checkConstructorIsCreatorAnnotated(member) { hasCreatorAnnotation(it) }
117-
else
118-
false
115+
// TODO: possible work around for JsonValue class that requires the class constructor to have the JsonCreator(DELEGATED) set?
116+
// since we infer the creator at times for these methods, the wrong mode could be implied.
117+
override fun findCreatorAnnotation(config: MapperConfig<*>, ann: Annotated): JsonCreator.Mode? {
118+
if (ann !is AnnotatedConstructor || !ann.isKotlinConstructorWithParameters()) return null
119+
120+
return JsonCreator.Mode.DEFAULT.takeIf {
121+
cache.checkConstructorIsCreatorAnnotated(ann) { hasCreatorAnnotation(it) }
122+
}
123+
}
119124

120125
@Suppress("UNCHECKED_CAST")
121126
private fun findKotlinParameterName(param: AnnotatedParameter): String? {

0 commit comments

Comments
 (0)