Skip to content

Commit e7d73ac

Browse files
committed
add experimentalDeserializationBackend switch
1 parent 5845e0b commit e7d73ac

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ enum class KotlinFeature(val enabledByDefault: Boolean) {
88
NullToEmptyMap(enabledByDefault = false),
99
NullIsSameAsDefault(enabledByDefault = false),
1010
SingletonSupport(enabledByDefault = false),
11-
StrictNullChecks(enabledByDefault = false);
11+
StrictNullChecks(enabledByDefault = false),
12+
ExperimentalDeserializationBackend(enabledByDefault = false);
1213

1314
internal val bitSet: BitSet = 2.0.pow(ordinal).toInt().toBitSet()
1415
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,18 @@ fun Class<*>.isKotlinClass(): Boolean {
3131
* the default, collections which are typed to disallow null members
3232
* (e.g. List<String>) may contain null values after deserialization. Enabling it
3333
* protects against this but has significant performance impact.
34+
* @param experimentalDeserializationBackend
35+
* Default: false. Whether to enable experimental deserialization backend. Enabling
36+
* it significantly improve performance in certain use cases.
3437
*/
3538
class KotlinModule @Deprecated(level = DeprecationLevel.WARNING, message = "Use KotlinModule.Builder") constructor(
3639
val reflectionCacheSize: Int = 512,
3740
val nullToEmptyCollection: Boolean = false,
3841
val nullToEmptyMap: Boolean = false,
3942
val nullIsSameAsDefault: Boolean = false,
4043
val singletonSupport: SingletonSupport = DISABLED,
41-
val strictNullChecks: Boolean = false
44+
val strictNullChecks: Boolean = false,
45+
val experimentalDeserializationBackend: Boolean = false
4246
) : SimpleModule(PackageVersion.VERSION) {
4347
@Deprecated(level = DeprecationLevel.HIDDEN, message = "For ABI compatibility")
4448
constructor(
@@ -77,7 +81,8 @@ class KotlinModule @Deprecated(level = DeprecationLevel.WARNING, message = "Use
7781
builder.isEnabled(KotlinFeature.SingletonSupport) -> CANONICALIZE
7882
else -> DISABLED
7983
},
80-
builder.isEnabled(StrictNullChecks)
84+
builder.isEnabled(StrictNullChecks),
85+
builder.isEnabled(KotlinFeature.ExperimentalDeserializationBackend)
8186
)
8287

8388
companion object {
@@ -95,7 +100,14 @@ class KotlinModule @Deprecated(level = DeprecationLevel.WARNING, message = "Use
95100

96101
val cache = ReflectionCache(reflectionCacheSize)
97102

98-
context.addValueInstantiators(KotlinInstantiators(cache, nullToEmptyCollection, nullToEmptyMap, nullIsSameAsDefault, strictNullChecks))
103+
context.addValueInstantiators(KotlinInstantiators(
104+
cache,
105+
nullToEmptyCollection,
106+
nullToEmptyMap,
107+
nullIsSameAsDefault,
108+
strictNullChecks,
109+
experimentalDeserializationBackend
110+
))
99111

100112
when (singletonSupport) {
101113
DISABLED -> Unit

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ internal class KotlinValueInstantiator(
2929
private val nullToEmptyCollection: Boolean,
3030
private val nullToEmptyMap: Boolean,
3131
private val nullIsSameAsDefault: Boolean,
32-
private val strictNullChecks: Boolean
32+
private val strictNullChecks: Boolean,
33+
private val experimentalDeserializationBackend: Boolean
3334
) : StdValueInstantiator(src) {
3435
@Suppress("UNCHECKED_CAST")
3536
override fun createFromObjectWith(
@@ -188,7 +189,8 @@ internal class KotlinInstantiators(
188189
private val nullToEmptyCollection: Boolean,
189190
private val nullToEmptyMap: Boolean,
190191
private val nullIsSameAsDefault: Boolean,
191-
private val strictNullChecks: Boolean
192+
private val strictNullChecks: Boolean,
193+
private val experimentalDeserializationBackend: Boolean
192194
) : ValueInstantiators {
193195
override fun findValueInstantiator(
194196
deserConfig: DeserializationConfig,
@@ -197,7 +199,15 @@ internal class KotlinInstantiators(
197199
): ValueInstantiator {
198200
return if (beanDescriptor.beanClass.isKotlinClass()) {
199201
if (defaultInstantiator is StdValueInstantiator) {
200-
KotlinValueInstantiator(defaultInstantiator, cache, nullToEmptyCollection, nullToEmptyMap, nullIsSameAsDefault, strictNullChecks)
202+
KotlinValueInstantiator(
203+
defaultInstantiator,
204+
cache,
205+
nullToEmptyCollection,
206+
nullToEmptyMap,
207+
nullIsSameAsDefault,
208+
strictNullChecks,
209+
experimentalDeserializationBackend
210+
)
201211
} else {
202212
// TODO: return defaultInstantiator and let default method parameters and nullability go unused? or die with exception:
203213
throw IllegalStateException("KotlinValueInstantiator requires that the default ValueInstantiator is StdValueInstantiator")

0 commit comments

Comments
 (0)