Skip to content

Commit

Permalink
Merge pull request #747 from k163377/kotlin-module-perf
Browse files Browse the repository at this point in the history
Improved performance related to KotlinModule initialization and setupModule.
  • Loading branch information
k163377 committed Dec 30, 2023
2 parents 22838e5 + a33dbf5 commit f075e75
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 24 deletions.
1 change: 1 addition & 0 deletions pom.xml
Expand Up @@ -236,6 +236,7 @@
<exclude>com.fasterxml.jackson.module.kotlin.SequenceSerializer</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule#serialVersionUID</exclude>
<!-- internal -->
<exclude>com.fasterxml.jackson.module.kotlin.KotlinNamesAnnotationIntrospector</exclude>
</excludes>
</parameter>
</configuration>
Expand Down
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Expand Up @@ -18,6 +18,7 @@ Contributors:
# 2.17.0 (not yet released)

WrongWrong (@k163377)
* #747: Improved performance related to KotlinModule initialization and setupModule.
* #746: The KotlinModule#serialVersionUID is set to private.
* #745: Modified isKotlinClass determination method.
* #744: API deprecation update for KotlinModule.
Expand Down
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Expand Up @@ -18,6 +18,8 @@ Co-maintainers:

2.17.0 (not yet released)

#747: Improved performance related to KotlinModule initialization and setupModule.
With this change, the KotlinModule initialization error when using Kotlin 1.4 or lower has been eliminated.
#746: The KotlinModule#serialVersionUID is set to private.
#745: Modified isKotlinClass determination method.
#744: Functions that were already marked as deprecated,
Expand Down
@@ -1,6 +1,5 @@
package com.fasterxml.jackson.module.kotlin

import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.MapperFeature
import com.fasterxml.jackson.databind.module.SimpleModule
import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullIsSameAsDefault
Expand Down Expand Up @@ -62,16 +61,6 @@ class KotlinModule @Deprecated(
private const val serialVersionUID = 2L
}

init {
if (!KotlinVersion.CURRENT.isAtLeast(1, 5)) {
// Kotlin 1.4 was deprecated when this process was introduced(jackson-module-kotlin 2.15).
throw JsonMappingException(
null,
"KotlinModule requires Kotlin version >= 1.5 - Found ${KotlinVersion.CURRENT}"
)
}
}

@Deprecated(
level = DeprecationLevel.HIDDEN,
message = "If you have no choice but to initialize KotlinModule from reflection, use this constructor."
Expand Down Expand Up @@ -151,7 +140,6 @@ class KotlinModule @Deprecated(
))
context.appendAnnotationIntrospector(
KotlinNamesAnnotationIntrospector(
this,
cache,
ignoredClassesForImplyingJsonCreator,
useKotlinPropertyNameForGetter)
Expand All @@ -162,15 +150,8 @@ class KotlinModule @Deprecated(
context.addSerializers(KotlinSerializers())
context.addKeySerializers(KotlinKeySerializers())

fun addMixIn(clazz: Class<*>, mixin: Class<*>) {
context.setMixInAnnotations(clazz, mixin)
}

// ranges
addMixIn(IntRange::class.java, ClosedRangeMixin::class.java)
addMixIn(CharRange::class.java, ClosedRangeMixin::class.java)
addMixIn(LongRange::class.java, ClosedRangeMixin::class.java)
addMixIn(ClosedRange::class.java, ClosedRangeMixin::class.java)
context.setMixInAnnotations(ClosedRange::class.java, ClosedRangeMixin::class.java)
}

class Builder {
Expand Down
Expand Up @@ -26,10 +26,9 @@ import kotlin.reflect.jvm.javaType
import kotlin.reflect.jvm.kotlinFunction

internal class KotlinNamesAnnotationIntrospector(
val module: KotlinModule,
val cache: ReflectionCache,
val ignoredClassesForImplyingJsonCreator: Set<KClass<*>>,
val useKotlinPropertyNameForGetter: Boolean
private val cache: ReflectionCache,
private val ignoredClassesForImplyingJsonCreator: Set<KClass<*>>,
private val useKotlinPropertyNameForGetter: Boolean
) : NopAnnotationIntrospector() {
private fun getterNameFromJava(member: AnnotatedMethod): String? {
val name = member.name
Expand Down

0 comments on commit f075e75

Please sign in to comment.