From ae4e511323503a19e01e5456a397f628a2f65873 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Fri, 12 Jan 2024 22:49:45 +0900 Subject: [PATCH] Deprecated SingletonSupport --- .../com/fasterxml/jackson/module/kotlin/KotlinModule.kt | 8 ++++++++ .../fasterxml/jackson/module/kotlin/SingletonSupport.kt | 5 +++++ .../fasterxml/jackson/module/kotlin/KotlinModuleTest.kt | 2 ++ 3 files changed, 15 insertions(+) diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt index 67fdabdd..4da0baaf 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt @@ -25,6 +25,8 @@ fun Class<*>.isKotlinClass(): Boolean = this.isAnnotationPresent(Metadata::class * using the default value provided in Kotlin. * @property singletonSupport Default: DISABLED. Mode for singleton handling. * See {@link com.fasterxml.jackson.module.kotlin.SingletonSupport label} + * @property enabledSingletonSupport Default: false. A temporary property that is maintained until the return value of `singletonSupport` is changed. + * It will be removed in 2.21. * @property strictNullChecks Default: false. Whether to check deserialized collections. With this disabled, * the default, collections which are typed to disallow null members * (e.g. List) may contain null values after deserialization. Enabling it @@ -53,6 +55,11 @@ class KotlinModule @Deprecated( val nullToEmptyCollection: Boolean = NullToEmptyCollection.enabledByDefault, val nullToEmptyMap: Boolean = NullToEmptyMap.enabledByDefault, val nullIsSameAsDefault: Boolean = NullIsSameAsDefault.enabledByDefault, + @property:Deprecated( + level = DeprecationLevel.WARNING, + message = "The return value will be Boolean in 2.19. Until then, use enabledSingletonSupport.", + replaceWith = ReplaceWith("enabledSingletonSupport") + ) val singletonSupport: SingletonSupport = DISABLED, val strictNullChecks: Boolean = StrictNullChecks.enabledByDefault, @Deprecated( @@ -65,6 +72,7 @@ class KotlinModule @Deprecated( val useJavaDurationConversion: Boolean = UseJavaDurationConversion.enabledByDefault, ) : SimpleModule(KotlinModule::class.java.name, PackageVersion.VERSION) { val kotlinPropertyNameAsImplicitName: Boolean get() = useKotlinPropertyNameForGetter + val enabledSingletonSupport: Boolean get() = singletonSupport == CANONICALIZE companion object { // Increment when option is added diff --git a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/SingletonSupport.kt b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/SingletonSupport.kt index 5aa5eb2e..08da0ac5 100644 --- a/src/main/kotlin/com/fasterxml/jackson/module/kotlin/SingletonSupport.kt +++ b/src/main/kotlin/com/fasterxml/jackson/module/kotlin/SingletonSupport.kt @@ -3,6 +3,11 @@ package com.fasterxml.jackson.module.kotlin /** * Special handling for singletons. */ +@Deprecated( + level = DeprecationLevel.WARNING, + message = "It will be removed in 2.19 to unify with KotlinFeature.", + replaceWith = ReplaceWith("KotlinFeature.SingletonSupport") +) enum class SingletonSupport { // No special handling of singletons (pre-2.10 behavior) // Each time a Singleton object is deserialized a new instance is created. diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModuleTest.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModuleTest.kt index 1e6b2592..d3ed60e3 100644 --- a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModuleTest.kt +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModuleTest.kt @@ -18,6 +18,7 @@ class KotlinModuleTest { assertFalse(module.nullToEmptyMap) assertFalse(module.nullIsSameAsDefault) assertEquals(SingletonSupport.DISABLED, module.singletonSupport) + assertFalse(module.enabledSingletonSupport) assertFalse(module.strictNullChecks) assertFalse(module.kotlinPropertyNameAsImplicitName) assertFalse(module.useJavaDurationConversion) @@ -41,6 +42,7 @@ class KotlinModuleTest { assertTrue(module.nullToEmptyMap) assertTrue(module.nullIsSameAsDefault) assertEquals(SingletonSupport.CANONICALIZE, module.singletonSupport) + assertTrue(module.enabledSingletonSupport) assertTrue(module.strictNullChecks) assertTrue(module.kotlinPropertyNameAsImplicitName) assertTrue(module.useJavaDurationConversion)