Skip to content

Improved performance related to KotlinModule initialization and setupModule. #747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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