Skip to content

Commit 37cfc5d

Browse files
authored
Merge pull request #646 from k163377/drop-kotlin-1.4
In 2.15, fixed to not be able to use Kotlin 1.4 or lower.
2 parents 581cb83 + 2a09127 commit 37cfc5d

File tree

2 files changed

+36
-31
lines changed

2 files changed

+36
-31
lines changed

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

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -65,40 +65,34 @@ internal class KotlinAnnotationIntrospector(private val context: Module.SetupCon
6565
// Find a serializer to handle the case where the getter returns an unboxed value from the value class.
6666
override fun findSerializer(am: Annotated): StdSerializer<*>? = when (am) {
6767
is AnnotatedMethod -> {
68-
when (KotlinVersion.CURRENT.isAtLeast(1, 5)) {
69-
true -> {
70-
val getter = am.member.apply {
71-
// If the return value of the getter is a value class,
72-
// it will be serialized properly without doing anything.
73-
if (this.returnType.isUnboxableValueClass()) return null
68+
val getter = am.member.apply {
69+
// If the return value of the getter is a value class,
70+
// it will be serialized properly without doing anything.
71+
if (this.returnType.isUnboxableValueClass()) return null
72+
}
73+
74+
val kotlinProperty = getter
75+
.declaringClass
76+
.kotlin
77+
.let {
78+
// KotlinReflectionInternalError is raised in GitHub167 test,
79+
// but it looks like an edge case, so it is ignored.
80+
try {
81+
it.memberProperties
82+
} catch (e: Error) {
83+
null
7484
}
85+
}?.find { it.javaGetter == getter }
7586

76-
val kotlinProperty = getter
77-
.declaringClass
78-
.kotlin
79-
.let {
80-
// KotlinReflectionInternalError is raised in GitHub167 test,
81-
// but it looks like an edge case, so it is ignored.
82-
try {
83-
it.memberProperties
84-
} catch (e: Error) {
85-
null
86-
}
87-
}?.find { it.javaGetter == getter }
88-
89-
(kotlinProperty?.returnType?.classifier as? KClass<*>)
90-
?.takeIf { it.isValue }
91-
?.java
92-
?.let { outerClazz ->
93-
val innerClazz = getter.returnType
94-
95-
ValueClassStaticJsonValueSerializer.createdOrNull(outerClazz, innerClazz)
96-
?: @Suppress("UNCHECKED_CAST") ValueClassBoxSerializer(outerClazz, innerClazz)
97-
}
87+
(kotlinProperty?.returnType?.classifier as? KClass<*>)
88+
?.takeIf { it.isValue }
89+
?.java
90+
?.let { outerClazz ->
91+
val innerClazz = getter.returnType
92+
93+
ValueClassStaticJsonValueSerializer.createdOrNull(outerClazz, innerClazz)
94+
?: @Suppress("UNCHECKED_CAST") ValueClassBoxSerializer(outerClazz, innerClazz)
9895
}
99-
// Kotlin 1.4 and lower doesn't have value classes and we avoid the NoSuchMethodException on it.isValue
100-
else -> null
101-
}
10296
}
10397
// Ignore the case of AnnotatedField, because JvmField cannot be set in the field of value class.
10498
else -> null

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.module.kotlin
22

3+
import com.fasterxml.jackson.databind.JsonMappingException
34
import com.fasterxml.jackson.databind.MapperFeature
45
import com.fasterxml.jackson.databind.module.SimpleModule
56
import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullIsSameAsDefault
@@ -54,6 +55,16 @@ class KotlinModule @Deprecated(
5455
val singletonSupport: SingletonSupport = DISABLED,
5556
val strictNullChecks: Boolean = false
5657
) : SimpleModule(KotlinModule::class.java.name, PackageVersion.VERSION) {
58+
init {
59+
if (!KotlinVersion.CURRENT.isAtLeast(1, 5)) {
60+
// Kotlin 1.4 was deprecated when this process was introduced(jackson-module-kotlin 2.15).
61+
throw JsonMappingException(
62+
null,
63+
"KotlinModule requires Kotlin version >= 1.5 - Found ${KotlinVersion.CURRENT}"
64+
)
65+
}
66+
}
67+
5768
@Deprecated(level = DeprecationLevel.HIDDEN, message = "For ABI compatibility")
5869
constructor(
5970
reflectionCacheSize: Int,

0 commit comments

Comments
 (0)