From ae4e511323503a19e01e5456a397f628a2f65873 Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Fri, 12 Jan 2024 22:49:45 +0900 Subject: [PATCH 1/2] 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) From 0387f2780cffd3709c999fde1311b4452b4f296a Mon Sep 17 00:00:00 2001 From: wrongwrong Date: Fri, 12 Jan 2024 23:02:44 +0900 Subject: [PATCH 2/2] Update release notes wrt #758 --- release-notes/CREDITS-2.x | 1 + release-notes/VERSION-2.x | 1 + 2 files changed, 2 insertions(+) diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 05f01ef3..5eac8a3a 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -18,6 +18,7 @@ Contributors: # 2.17.0 (not yet released) WrongWrong (@k163377) +* #758: Deprecated SingletonSupport. * #755: Changes in constructor invocation and argument management. * #752: Fix KDoc for KotlinModule. * #751: Marked useKotlinPropertyNameForGetter as deprecated. diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index a08d7c26..8f077ea8 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -18,6 +18,7 @@ Co-maintainers: 2.17.0 (not yet released) +#758: Deprecated SingletonSupport and related properties to be consistent with KotlinFeature.SingletonSupport. #755: Changes in constructor invocation and argument management. This change degrades performance in cases where the constructor is called without default arguments, but improves performance in other cases. #751: The KotlinModule#useKotlinPropertyNameForGetter property was deprecated because it differed from the name of the KotlinFeature.