Skip to content

Commit 2e076ba

Browse files
authored
Refactor hasCreatorAnnotation method logic (#763)
* Refactor hasCreatorAnnotation method logic * Refactor hasCreatorAnnotation method in ScalaAnnotationIntrospectorModule
1 parent a7cdcfc commit 2e076ba

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/main/scala/com/fasterxml/jackson/module/scala/introspect/ScalaAnnotationIntrospectorModule.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,26 @@ object ScalaAnnotationIntrospector extends NopAnnotationIntrospector with ValueI
6161
}
6262

6363
override def hasCreatorAnnotation(a: Annotated): Boolean = {
64-
val jsonCreators: PartialFunction[Annotation, JsonCreator] = { case jc: JsonCreator => jc }
65-
6664
a match {
67-
case ac: AnnotatedConstructor if (!isScala(ac)) => false
68-
case ac: AnnotatedConstructor =>
65+
case ac: AnnotatedConstructor if isScala(ac) =>
6966
val annotatedFound = _descriptorFor(ac.getDeclaringClass).exists { d =>
7067
d.properties
7168
.flatMap(_.param)
7269
.exists(_.constructor == ac.getAnnotated)
7370
}
7471

72+
val jsonCreators: PartialFunction[Annotation, JsonCreator] = { case jc: JsonCreator => jc }
73+
7574
// Ignore this annotation if there is another annotation that is actually annotated with @JsonCreator.
76-
val annotatedConstructor = {
75+
def annotatedConstructor() = {
7776
for (constructor <- ac.getDeclaringClass.getDeclaredConstructors;
7877
annotation: JsonCreator <- constructor.getAnnotations.collect(jsonCreators) if annotation.mode() != JsonCreator.Mode.DISABLED) yield constructor
7978
}.headOption
8079

8180
// Ignore this annotation if it is Mode.DISABLED.
82-
val isDisabled = ac.getAnnotated.getAnnotations.collect(jsonCreators).exists(_.mode() == JsonCreator.Mode.DISABLED)
81+
def isDisabled() = ac.getAnnotated.getAnnotations.collect(jsonCreators).exists(_.mode() == JsonCreator.Mode.DISABLED)
8382

84-
annotatedFound && annotatedConstructor.forall(_ == ac.getAnnotated) && !isDisabled
83+
annotatedFound && annotatedConstructor().forall(_ == ac.getAnnotated) && !isDisabled()
8584
case _ => false
8685
}
8786
}

0 commit comments

Comments
 (0)