Skip to content

Commit 6498661

Browse files
committed
Fixed hasRequiredMarker to not override processing by other modules
Inspired by FasterXML/jackson-module-kotlin#923
1 parent f9668de commit 6498661

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/main/kotlin/io/github/projectmapk/jackson/module/kogera/annotationIntrospector/KotlinPrimaryAnnotationIntrospector.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,18 @@ internal class KotlinPrimaryAnnotationIntrospector(
2929
// If JsonProperty.required is true, the behavior is clearly specified and the result is paramount.
3030
// Otherwise, the required is determined from the configuration and the definition on Kotlin.
3131
override fun hasRequiredMarker(m: AnnotatedMember): Boolean? {
32-
val byAnnotation = _findAnnotation(m, JSON_PROPERTY_CLASS)
33-
?.let { if (it.required) return true else false }
32+
return cache.getJmClass(m.member.declaringClass)?.let { jmClass ->
33+
// To avoid overwriting processing by other modules, annotations are checked after JmClass has been obtained
34+
_findAnnotation(m, JSON_PROPERTY_CLASS)
35+
?.let { if (it.required) return true }
3436

35-
return cache.getJmClass(m.member.declaringClass)?.let {
3637
when (m) {
37-
is AnnotatedField -> m.hasRequiredMarker(it)
38-
is AnnotatedMethod -> m.getRequiredMarkerFromCorrespondingAccessor(it)
39-
is AnnotatedParameter -> m.hasRequiredMarker(it)
38+
is AnnotatedField -> m.hasRequiredMarker(jmClass)
39+
is AnnotatedMethod -> m.getRequiredMarkerFromCorrespondingAccessor(jmClass)
40+
is AnnotatedParameter -> m.hasRequiredMarker(jmClass)
4041
else -> null
4142
}
42-
} ?: byAnnotation // If a JsonProperty is available, use it to reduce processing costs.
43+
}
4344
}
4445

4546
// Functions that call this may return incorrect results for value classes whose value type is Collection or Map,

0 commit comments

Comments
 (0)