From e22bc28717a6f26e9f2dbaf987c3ea76cc6656ae Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 19 Nov 2023 18:11:41 +0900 Subject: [PATCH 1/3] Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation fixes #200 --- .../kotlin/KotlinNamesAnnotationIntrospector.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt index aaca6ccb..77abced6 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt @@ -2,6 +2,7 @@ package com.fasterxml.jackson.module.kotlin import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.databind.cfg.MapperConfig import com.fasterxml.jackson.databind.introspect.Annotated import com.fasterxml.jackson.databind.introspect.AnnotatedConstructor import com.fasterxml.jackson.databind.introspect.AnnotatedMember @@ -111,11 +112,13 @@ internal class KotlinNamesAnnotationIntrospector( } } - override fun hasCreatorAnnotation(member: Annotated): Boolean = - if (member is AnnotatedConstructor && member.isKotlinConstructorWithParameters()) - cache.checkConstructorIsCreatorAnnotated(member) { hasCreatorAnnotation(it) } - else - false + override fun findCreatorAnnotation(config: MapperConfig<*>, ann: Annotated): JsonCreator.Mode? { + if (ann !is AnnotatedConstructor || !ann.isKotlinConstructorWithParameters()) return null + + return JsonCreator.Mode.DEFAULT.takeIf { + cache.checkConstructorIsCreatorAnnotated(ann) { hasCreatorAnnotation(it) } + } + } @Suppress("UNCHECKED_CAST") private fun findKotlinParameterName(param: AnnotatedParameter): String? { From 3b6d46adc437b48c362c4e39586b31262b4e259f Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Sun, 19 Nov 2023 18:29:41 +0900 Subject: [PATCH 2/3] Update release notes wrt #727 --- release-notes/CREDITS-2.x | 1 + release-notes/VERSION-2.x | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 5ee73efe..3ae243a1 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -16,6 +16,7 @@ Authors: Contributors: # 2.17.0 (not yet released) +* #727: Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation # 2.16.0 diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 707dcdf1..85677a03 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -18,7 +18,7 @@ Co-maintainers: 2.17.0 (not yet released) -- +#727: Fixed overriding findCreatorAnnotation instead of hasCreatorAnnotation. 2.16.0 (15-Nov-2023) From 23e8185dc0c12240494e565c51c437fe777b54d9 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Mon, 20 Nov 2023 09:20:40 +0900 Subject: [PATCH 3/3] Move TODO --- .../module/kotlin/KotlinAnnotationIntrospector.kt | 11 ----------- .../kotlin/KotlinNamesAnnotationIntrospector.kt | 2 ++ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinAnnotationIntrospector.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinAnnotationIntrospector.kt index a06bd014..bd61b979 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinAnnotationIntrospector.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinAnnotationIntrospector.kt @@ -1,11 +1,9 @@ package com.fasterxml.jackson.module.kotlin -import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.databind.DeserializationFeature import com.fasterxml.jackson.databind.JsonSerializer import com.fasterxml.jackson.databind.Module -import com.fasterxml.jackson.databind.cfg.MapperConfig import com.fasterxml.jackson.databind.introspect.* import com.fasterxml.jackson.databind.jsontype.NamedType import com.fasterxml.jackson.databind.util.Converter @@ -59,15 +57,6 @@ internal class KotlinAnnotationIntrospector( return hasRequired } - override fun findCreatorAnnotation(config: MapperConfig<*>, a: Annotated): JsonCreator.Mode? { - - // TODO: possible work around for JsonValue class that requires the class constructor to have the JsonCreator(Mode.DELEGATED) set? - // since we infer the creator at times for these methods, the wrong mode could be implied. - - // 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 - return super.findCreatorAnnotation(config, a) - } - override fun findSerializationConverter(a: Annotated): Converter<*, *>? = when (a) { // Find a converter to handle the case where the getter returns an unboxed value from the value class. is AnnotatedMethod -> a.findValueClassReturnType()?.let { diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt index 77abced6..babe8e92 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt @@ -112,6 +112,8 @@ internal class KotlinNamesAnnotationIntrospector( } } + // TODO: possible work around for JsonValue class that requires the class constructor to have the JsonCreator(DELEGATED) set? + // since we infer the creator at times for these methods, the wrong mode could be implied. override fun findCreatorAnnotation(config: MapperConfig<*>, ann: Annotated): JsonCreator.Mode? { if (ann !is AnnotatedConstructor || !ann.isKotlinConstructorWithParameters()) return null