From a2112daabce71e71deb6ab9558d391df5a4ced57 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 4 Sep 2025 01:29:25 +0100 Subject: [PATCH 1/2] Refactor hasCreatorAnnotation method logic --- .../ScalaAnnotationIntrospectorModule.scala | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala b/src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala index 4d389eed..cb928c44 100644 --- a/src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala +++ b/src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala @@ -64,24 +64,23 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector with ValueI val jsonCreators: PartialFunction[Annotation, JsonCreator] = { case jc: JsonCreator => jc } a match { - case ac: AnnotatedConstructor if (!isScala(ac)) => false - case ac: AnnotatedConstructor => - val annotatedFound = _descriptorFor(ac.getDeclaringClass).exists { d => + case ac: AnnotatedConstructor if isScala(ac) => + def annotatedFound() = _descriptorFor(ac.getDeclaringClass).exists { d => d.properties .flatMap(_.param) .exists(_.constructor == ac.getAnnotated) } // Ignore this annotation if there is another annotation that is actually annotated with @JsonCreator. - val annotatedConstructor = { + def annotatedConstructor() = { for (constructor <- ac.getDeclaringClass.getDeclaredConstructors; annotation: JsonCreator <- constructor.getAnnotations.collect(jsonCreators) if annotation.mode() != JsonCreator.Mode.DISABLED) yield constructor }.headOption // Ignore this annotation if it is Mode.DISABLED. - val isDisabled = ac.getAnnotated.getAnnotations.collect(jsonCreators).exists(_.mode() == JsonCreator.Mode.DISABLED) + def isDisabled() = ac.getAnnotated.getAnnotations.collect(jsonCreators).exists(_.mode() == JsonCreator.Mode.DISABLED) - annotatedFound && annotatedConstructor.forall(_ == ac.getAnnotated) && !isDisabled + annotatedFound() && annotatedConstructor().forall(_ == ac.getAnnotated) && !isDisabled() case _ => false } } From 449a2c19e0606b39cbd92c44afeca203c43458d8 Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Thu, 4 Sep 2025 01:41:14 +0100 Subject: [PATCH 2/2] Refactor hasCreatorAnnotation method in ScalaAnnotationIntrospectorModule --- .../introspect/ScalaAnnotationIntrospectorModule.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala b/src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala index cb928c44..b8ae2c72 100644 --- a/src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala +++ b/src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala @@ -61,16 +61,16 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector with ValueI } override def hasCreatorAnnotation(a: Annotated): Boolean = { - val jsonCreators: PartialFunction[Annotation, JsonCreator] = { case jc: JsonCreator => jc } - a match { case ac: AnnotatedConstructor if isScala(ac) => - def annotatedFound() = _descriptorFor(ac.getDeclaringClass).exists { d => + val annotatedFound = _descriptorFor(ac.getDeclaringClass).exists { d => d.properties .flatMap(_.param) .exists(_.constructor == ac.getAnnotated) } + val jsonCreators: PartialFunction[Annotation, JsonCreator] = { case jc: JsonCreator => jc } + // Ignore this annotation if there is another annotation that is actually annotated with @JsonCreator. def annotatedConstructor() = { for (constructor <- ac.getDeclaringClass.getDeclaredConstructors; @@ -80,7 +80,7 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector with ValueI // Ignore this annotation if it is Mode.DISABLED. def isDisabled() = ac.getAnnotated.getAnnotations.collect(jsonCreators).exists(_.mode() == JsonCreator.Mode.DISABLED) - annotatedFound() && annotatedConstructor().forall(_ == ac.getAnnotated) && !isDisabled() + annotatedFound && annotatedConstructor().forall(_ == ac.getAnnotated) && !isDisabled() case _ => false } }