File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed
src/main/kotlin/com/fasterxml/jackson/module/kotlin Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Contributors:
1818# 2 .19.0 (not yet released)
1919
2020WrongWrong (@k163377 )
21+ * #858 : Refactor findDefaultCreator
2122* #839 : Remove useKotlinPropertyNameForGetter and unify with kotlinPropertyNameAsImplicitName
2223* #835 : Remove old SingletonSupport class and unified with KotlinFeature.SingletonSupport
2324
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ Co-maintainers:
1818
19192.19 .0 (not yet released )
2020
21+ #858 : Minor performance improvement of findDefaultCreator in edge cases .
2122#839 : Remove useKotlinPropertyNameForGetter and unify with kotlinPropertyNameAsImplicitName .
2223#835 : Remove old SingletonSupport class and unified with KotlinFeature .SingletonSupport .
2324
Original file line number Diff line number Diff line change @@ -91,13 +91,11 @@ internal class KotlinNamesAnnotationIntrospector(
9191 ): PotentialCreator ? {
9292 val kClass = valueClass.creatableKotlinClass() ? : return null
9393
94- val propertyNames = kClass.memberProperties.map { it.name }.toSet()
95-
96- val defaultCreator = kClass.let { _ ->
97- // By default, the primary constructor or the only publicly available constructor may be used
98- val ctor = kClass.primaryConstructor ? : kClass.constructors.takeIf { it.size == 1 }?.single()
99- ctor?.takeIf { it.isPossibleCreator(propertyNames) }
100- }
94+ val defaultCreator = kClass.primarilyConstructor()
95+ ?.takeIf { ctor ->
96+ val propertyNames = kClass.memberProperties.map { it.name }.toSet()
97+ ctor.isPossibleCreator(propertyNames)
98+ }
10199 ? : return null
102100
103101 return declaredConstructors.find {
@@ -115,6 +113,9 @@ private fun AnnotatedClass.creatableKotlinClass(): KClass<*>? = annotated
115113 .takeIf { it.isKotlinClass() && ! it.isEnum }
116114 ?.kotlin
117115
116+ // By default, the primary constructor or the only publicly available constructor may be used
117+ private fun KClass <* >.primarilyConstructor () = primaryConstructor ? : constructors.singleOrNull()
118+
118119private fun KFunction <* >.isPossibleCreator (propertyNames : Set <String >): Boolean = 0 < parameters.size
119120 && ! isPossibleSingleString(propertyNames)
120121 && parameters.none { it.name == null }
You can’t perform that action at this time.
0 commit comments