Cut out conditionals and reduce nesting
MODIFY
src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt
src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt
@@ -58,13 +58,15 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
return null
}
+ // if has parameters, is a Kotlin class, and the parameters all have parameter annotations, then pretend we have a JsonCreator
+ private fun AnnotatedConstructor.isKotlinConstructorWithParameters(): Boolean =
+ parameterCount > 0 && declaringClass.isKotlinClass() && !declaringClass.isEnum
+
@Suppress("UNCHECKED_CAST")
override fun hasCreatorAnnotation(member: Annotated): Boolean {
// don't add a JsonCreator to any constructor if one is declared already
- if (member is AnnotatedConstructor && !member.declaringClass.isEnum) {
- // if has parameters, is a Kotlin class, and the parameters all have parameter annotations, then pretend we have a JsonCreator
- if (member.parameterCount > 0 && member.declaringClass.isKotlinClass()) {
+ if (member is AnnotatedConstructor && member.isKotlinConstructorWithParameters()) {
return cache.checkConstructorIsCreatorAnnotated(member) {
val kClass = cache.kotlinFromJava(member.declaringClass as Class<Any>)
val kConstructor = cache.kotlinFromJava(member.annotated as Constructor<Any>)
@@ -117,7 +119,6 @@ internal class KotlinNamesAnnotationIntrospector(val module: KotlinModule, val c
}
}
}
- }
return false
}

Cut out conditionals and reduce nesting