Skip to content

Commit f075e75

Browse files
authored
Merge pull request #747 from k163377/kotlin-module-perf
Improved performance related to KotlinModule initialization and setupModule.
2 parents 22838e5 + a33dbf5 commit f075e75

File tree

5 files changed

+8
-24
lines changed

5 files changed

+8
-24
lines changed

pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
<exclude>com.fasterxml.jackson.module.kotlin.SequenceSerializer</exclude>
237237
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule#serialVersionUID</exclude>
238238
<!-- internal -->
239+
<exclude>com.fasterxml.jackson.module.kotlin.KotlinNamesAnnotationIntrospector</exclude>
239240
</excludes>
240241
</parameter>
241242
</configuration>

release-notes/CREDITS-2.x

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Contributors:
1818
# 2.17.0 (not yet released)
1919

2020
WrongWrong (@k163377)
21+
* #747: Improved performance related to KotlinModule initialization and setupModule.
2122
* #746: The KotlinModule#serialVersionUID is set to private.
2223
* #745: Modified isKotlinClass determination method.
2324
* #744: API deprecation update for KotlinModule.

release-notes/VERSION-2.x

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Co-maintainers:
1818

1919
2.17.0 (not yet released)
2020

21+
#747: Improved performance related to KotlinModule initialization and setupModule.
22+
With this change, the KotlinModule initialization error when using Kotlin 1.4 or lower has been eliminated.
2123
#746: The KotlinModule#serialVersionUID is set to private.
2224
#745: Modified isKotlinClass determination method.
2325
#744: Functions that were already marked as deprecated,

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.fasterxml.jackson.module.kotlin
22

3-
import com.fasterxml.jackson.databind.JsonMappingException
43
import com.fasterxml.jackson.databind.MapperFeature
54
import com.fasterxml.jackson.databind.module.SimpleModule
65
import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullIsSameAsDefault
@@ -62,16 +61,6 @@ class KotlinModule @Deprecated(
6261
private const val serialVersionUID = 2L
6362
}
6463

65-
init {
66-
if (!KotlinVersion.CURRENT.isAtLeast(1, 5)) {
67-
// Kotlin 1.4 was deprecated when this process was introduced(jackson-module-kotlin 2.15).
68-
throw JsonMappingException(
69-
null,
70-
"KotlinModule requires Kotlin version >= 1.5 - Found ${KotlinVersion.CURRENT}"
71-
)
72-
}
73-
}
74-
7564
@Deprecated(
7665
level = DeprecationLevel.HIDDEN,
7766
message = "If you have no choice but to initialize KotlinModule from reflection, use this constructor."
@@ -151,7 +140,6 @@ class KotlinModule @Deprecated(
151140
))
152141
context.appendAnnotationIntrospector(
153142
KotlinNamesAnnotationIntrospector(
154-
this,
155143
cache,
156144
ignoredClassesForImplyingJsonCreator,
157145
useKotlinPropertyNameForGetter)
@@ -162,15 +150,8 @@ class KotlinModule @Deprecated(
162150
context.addSerializers(KotlinSerializers())
163151
context.addKeySerializers(KotlinKeySerializers())
164152

165-
fun addMixIn(clazz: Class<*>, mixin: Class<*>) {
166-
context.setMixInAnnotations(clazz, mixin)
167-
}
168-
169153
// ranges
170-
addMixIn(IntRange::class.java, ClosedRangeMixin::class.java)
171-
addMixIn(CharRange::class.java, ClosedRangeMixin::class.java)
172-
addMixIn(LongRange::class.java, ClosedRangeMixin::class.java)
173-
addMixIn(ClosedRange::class.java, ClosedRangeMixin::class.java)
154+
context.setMixInAnnotations(ClosedRange::class.java, ClosedRangeMixin::class.java)
174155
}
175156

176157
class Builder {

src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinNamesAnnotationIntrospector.kt

+3-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ import kotlin.reflect.jvm.javaType
2626
import kotlin.reflect.jvm.kotlinFunction
2727

2828
internal class KotlinNamesAnnotationIntrospector(
29-
val module: KotlinModule,
30-
val cache: ReflectionCache,
31-
val ignoredClassesForImplyingJsonCreator: Set<KClass<*>>,
32-
val useKotlinPropertyNameForGetter: Boolean
29+
private val cache: ReflectionCache,
30+
private val ignoredClassesForImplyingJsonCreator: Set<KClass<*>>,
31+
private val useKotlinPropertyNameForGetter: Boolean
3332
) : NopAnnotationIntrospector() {
3433
private fun getterNameFromJava(member: AnnotatedMethod): String? {
3534
val name = member.name

0 commit comments

Comments
 (0)