Skip to content
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

Organize deprecated contents #782

Merged
merged 8 commits into from
Apr 5, 2024
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
27 changes: 14 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@
-->
<!-- 30-Sep-2023, wrongwrong: For 2.16, compare to 2.15.2 baseline
-->
<version>2.16.0</version>
<version>2.17.0</version>
<type>jar</type>
</dependency>
</oldVersion>
Expand All @@ -239,19 +239,20 @@
<excludes>
<!-- public -->
<!-- removed -->
<exclude>com.fasterxml.jackson.module.kotlin.SequenceSerializer</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule#serialVersionUID</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule#KotlinModule(int,boolean,boolean,boolean,com.fasterxml.jackson.module.kotlin.SingletonSupport,boolean,boolean,boolean)</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#getNullIsSameAsDefault()</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#nullIsSameAsDefault(boolean)</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#getNullToEmptyCollection()</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#nullToEmptyCollection(boolean)</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#getNullToEmptyMap()</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#nullToEmptyMap(boolean)</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#getSingletonSupport()</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#singletonSupport(com.fasterxml.jackson.module.kotlin.SingletonSupport)</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#getStrictNullChecks()</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#strictNullChecks(boolean)</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinModule$Builder#reflectionCacheSize(int)</exclude>
<!-- internal -->
<exclude>com.fasterxml.jackson.module.kotlin.KotlinNamesAnnotationIntrospector</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.ValueCreator</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.ConstructorValueCreator</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.MethodValueCreator</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.TypesKt</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.KotlinDeserializers</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.ExtensionsKt#isUnboxableValueClass(java.lang.Class)</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.ExtensionsKt#toBitSet(int)</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.ExtensionsKt#wrapWithPath(com.fasterxml.jackson.databind.JsonMappingException,java.lang.Object,java.lang.String)</exclude>
<exclude>com.fasterxml.jackson.module.kotlin.ExtensionsKt#wrapWithPath(com.fasterxml.jackson.databind.JsonMappingException,java.lang.Object,int)</exclude>

</excludes>
</parameter>
</configuration>
Expand Down
3 changes: 3 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Authors:

Contributors:

# 2.18.0 (not yet released)
* #782: Organize deprecated contents

# 2.17.1 (not yet released)

WrongWrong (@k163377)
Expand Down
4 changes: 3 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Co-maintainers:

2.18.0 (not yet released)

No changes since 2.17
#782: Content marked as deprecated has been reorganized.
Several constructors and accessors to properties of KotlinModule.Builder that were marked as DeprecationLevel.ERROR have been removed.
Also, the content marked as DeprecationLevel.WARNING is now DeprecationLevel.ERROR.

2.17.1 (not yet released)

Expand Down
198 changes: 16 additions & 182 deletions src/main/kotlin/com/fasterxml/jackson/module/kotlin/KotlinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullToEmptyMap
import com.fasterxml.jackson.module.kotlin.KotlinFeature.StrictNullChecks
import com.fasterxml.jackson.module.kotlin.KotlinFeature.KotlinPropertyNameAsImplicitName
import com.fasterxml.jackson.module.kotlin.KotlinFeature.UseJavaDurationConversion
import com.fasterxml.jackson.module.kotlin.SingletonSupport.CANONICALIZE
import com.fasterxml.jackson.module.kotlin.SingletonSupport.DISABLED
import java.util.*
import kotlin.reflect.KClass

fun Class<*>.isKotlinClass(): Boolean = this.isAnnotationPresent(Metadata::class.java)

/**
* @constructor To avoid binary compatibility issues, the primary constructor is not published.
* Please use KotlinModule.Builder or extensions that use it.
* @property reflectionCacheSize Default: 512. Size, in items, of the caches used for mapping objects.
* @property nullToEmptyCollection Default: false. Whether to deserialize null values for collection properties as
* empty collections.
Expand All @@ -36,43 +36,32 @@ fun Class<*>.isKotlinClass(): Boolean = this.isAnnotationPresent(Metadata::class
* @property useJavaDurationConversion Default: false. Whether to use [java.time.Duration] as a bridge for [kotlin.time.Duration].
* This allows use Kotlin Duration type with [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule].
*/
class KotlinModule @Deprecated(
level = DeprecationLevel.ERROR,
message = "Use KotlinModule.Builder instead of named constructor parameters. It will be HIDDEN at 2.18.",
replaceWith = ReplaceWith(
"""KotlinModule.Builder()
.withReflectionCacheSize(reflectionCacheSize)
.configure(KotlinFeature.NullToEmptyCollection, nullToEmptyCollection)
.configure(KotlinFeature.NullToEmptyMap, nullToEmptyMap)
.configure(KotlinFeature.NullIsSameAsDefault, nullIsSameAsDefault)
.configure(KotlinFeature.SingletonSupport, singletonSupport)
.configure(KotlinFeature.StrictNullChecks, strictNullChecks)
.build()""",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
) constructor(
class KotlinModule private constructor(
val reflectionCacheSize: Int = Builder.DEFAULT_CACHE_SIZE,
val nullToEmptyCollection: Boolean = NullToEmptyCollection.enabledByDefault,
val nullToEmptyMap: Boolean = NullToEmptyMap.enabledByDefault,
val nullIsSameAsDefault: Boolean = NullIsSameAsDefault.enabledByDefault,
@property:Deprecated(
level = DeprecationLevel.WARNING,
level = DeprecationLevel.ERROR,
message = "The return value will be Boolean in 2.19. Until then, use enabledSingletonSupport.",
replaceWith = ReplaceWith("enabledSingletonSupport")
)
val singletonSupport: SingletonSupport = DISABLED,
@Suppress("DEPRECATION_ERROR")
val singletonSupport: SingletonSupport = SingletonSupport.DISABLED,
val strictNullChecks: Boolean = StrictNullChecks.enabledByDefault,
@Deprecated(
level = DeprecationLevel.WARNING,
level = DeprecationLevel.ERROR,
message = "There was a discrepancy between the property name and the Feature name." +
" To migrate to the correct property name, it will be ERROR in 2.18 and removed in 2.19.",
replaceWith = ReplaceWith("kotlinPropertyNameAsImplicitName")
)
val useKotlinPropertyNameForGetter: Boolean = KotlinPropertyNameAsImplicitName.enabledByDefault,
val useJavaDurationConversion: Boolean = UseJavaDurationConversion.enabledByDefault,
) : SimpleModule(KotlinModule::class.java.name, PackageVersion.VERSION) {
@Suppress("DEPRECATION_ERROR")
val kotlinPropertyNameAsImplicitName: Boolean get() = useKotlinPropertyNameForGetter
val enabledSingletonSupport: Boolean get() = singletonSupport == CANONICALIZE
@Suppress("DEPRECATION_ERROR")
val enabledSingletonSupport: Boolean get() = singletonSupport == SingletonSupport.CANONICALIZE

companion object {
// Increment when option is added
Expand All @@ -83,45 +72,17 @@ class KotlinModule @Deprecated(
level = DeprecationLevel.HIDDEN,
message = "If you have no choice but to initialize KotlinModule from reflection, use this constructor."
)
@Suppress("DEPRECATION_ERROR")
constructor() : this()

@Deprecated(level = DeprecationLevel.HIDDEN, message = "For ABI compatibility. It will be removed in 2.18.")
constructor(
reflectionCacheSize: Int,
nullToEmptyCollection: Boolean,
nullToEmptyMap: Boolean
) : this(
Builder()
.withReflectionCacheSize(reflectionCacheSize)
.configure(NullToEmptyCollection, nullToEmptyCollection)
.configure(NullToEmptyMap, nullToEmptyMap)
.disable(NullIsSameAsDefault)
)

@Deprecated(level = DeprecationLevel.HIDDEN, message = "For ABI compatibility. It will be removed in 2.18.")
constructor(
reflectionCacheSize: Int,
nullToEmptyCollection: Boolean,
nullToEmptyMap: Boolean,
nullIsSameAsDefault: Boolean
) : this(
Builder()
.withReflectionCacheSize(reflectionCacheSize)
.configure(NullToEmptyCollection, nullToEmptyCollection)
.configure(NullToEmptyMap, nullToEmptyMap)
.configure(NullIsSameAsDefault, nullIsSameAsDefault)
)

@Suppress("DEPRECATION_ERROR")
private constructor(builder: Builder) : this(
builder.reflectionCacheSize,
builder.isEnabled(NullToEmptyCollection),
builder.isEnabled(NullToEmptyMap),
builder.isEnabled(NullIsSameAsDefault),
@Suppress("DEPRECATION_ERROR")
when {
builder.isEnabled(KotlinFeature.SingletonSupport) -> CANONICALIZE
else -> DISABLED
builder.isEnabled(KotlinFeature.SingletonSupport) -> SingletonSupport.CANONICALIZE
else -> SingletonSupport.DISABLED
},
builder.isEnabled(StrictNullChecks),
builder.isEnabled(KotlinPropertyNameAsImplicitName),
Expand All @@ -141,11 +102,8 @@ class KotlinModule @Deprecated(

context.addValueInstantiators(KotlinInstantiators(cache, nullToEmptyCollection, nullToEmptyMap, nullIsSameAsDefault, strictNullChecks))

when (singletonSupport) {
DISABLED -> Unit
CANONICALIZE -> {
context.addBeanDeserializerModifier(KotlinBeanDeserializerModifier)
}
if (enabledSingletonSupport) {
context.addBeanDeserializerModifier(KotlinBeanDeserializerModifier)
}

context.insertAnnotationIntrospector(KotlinAnnotationIntrospector(
Expand All @@ -160,7 +118,7 @@ class KotlinModule @Deprecated(
KotlinNamesAnnotationIntrospector(
cache,
ignoredClassesForImplyingJsonCreator,
useKotlinPropertyNameForGetter)
kotlinPropertyNameAsImplicitName)
)

context.addDeserializers(KotlinDeserializers(cache, useJavaDurationConversion))
Expand Down Expand Up @@ -203,130 +161,6 @@ class KotlinModule @Deprecated(
fun isEnabled(feature: KotlinFeature): Boolean =
bitSet.intersects(feature.bitSet)

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use withReflectionCacheSize(reflectionCacheSize) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith("withReflectionCacheSize(reflectionCacheSize)")
)
fun reflectionCacheSize(reflectionCacheSize: Int): Builder =
withReflectionCacheSize(reflectionCacheSize)

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use isEnabled(NullToEmptyCollection) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"isEnabled(KotlinFeature.NullToEmptyCollection)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun getNullToEmptyCollection(): Boolean =
isEnabled(NullToEmptyCollection)

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use configure(NullToEmptyCollection, enabled) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"configure(KotlinFeature.NullToEmptyCollection, nullToEmptyCollection)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun nullToEmptyCollection(nullToEmptyCollection: Boolean): Builder =
configure(NullToEmptyCollection, nullToEmptyCollection)

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use isEnabled(NullToEmptyMap) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"isEnabled(KotlinFeature.NullToEmptyMap)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun getNullToEmptyMap(): Boolean =
isEnabled(NullToEmptyMap)

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use configure(NullToEmptyMap, enabled) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"configure(KotlinFeature.NullToEmptyMap, nullToEmptyMap)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun nullToEmptyMap(nullToEmptyMap: Boolean): Builder =
configure(NullToEmptyMap, nullToEmptyMap)

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use isEnabled(NullIsSameAsDefault) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"isEnabled(KotlinFeature.NullIsSameAsDefault)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun getNullIsSameAsDefault(): Boolean =
isEnabled(NullIsSameAsDefault)

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use configure(NullIsSameAsDefault, enabled) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"configure(KotlinFeature.NullIsSameAsDefault, nullIsSameAsDefault)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun nullIsSameAsDefault(nullIsSameAsDefault: Boolean): Builder =
configure(NullIsSameAsDefault, nullIsSameAsDefault)

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use isEnabled(SingletonSupport) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"isEnabled(KotlinFeature.SingletonSupport)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun getSingletonSupport(): SingletonSupport =
when {
isEnabled(KotlinFeature.SingletonSupport) -> CANONICALIZE
else -> DISABLED
}

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use configure(SingletonSupport, enabled) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"configure(KotlinFeature.SingletonSupport, singletonSupport)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun singletonSupport(singletonSupport: SingletonSupport): Builder =
when (singletonSupport) {
CANONICALIZE -> enable(KotlinFeature.SingletonSupport)
else -> disable(KotlinFeature.SingletonSupport)
}

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use isEnabled(StrictNullChecks) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"isEnabled(KotlinFeature.StrictNullChecks)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun getStrictNullChecks(): Boolean =
isEnabled(StrictNullChecks)

@Deprecated(
level = DeprecationLevel.ERROR,
message = "Deprecated, use configure(StrictNullChecks, enabled) instead. It will be removed in 2.18.",
replaceWith = ReplaceWith(
"configure(KotlinFeature.StrictNullChecks, strictNullChecks)",
"com.fasterxml.jackson.module.kotlin.KotlinFeature"
)
)
fun strictNullChecks(strictNullChecks: Boolean): Builder =
configure(StrictNullChecks, strictNullChecks)

fun build(): KotlinModule =
KotlinModule(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package com.fasterxml.jackson.module.kotlin
* Special handling for singletons.
*/
@Deprecated(
level = DeprecationLevel.WARNING,
level = DeprecationLevel.ERROR,
message = "It will be removed in 2.19 to unify with KotlinFeature.",
replaceWith = ReplaceWith("KotlinFeature.SingletonSupport")
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullToEmptyCollection
import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullToEmptyMap
import com.fasterxml.jackson.module.kotlin.KotlinFeature.SingletonSupport
import com.fasterxml.jackson.module.kotlin.KotlinFeature.StrictNullChecks
import com.fasterxml.jackson.module.kotlin.SingletonSupport.CANONICALIZE
import org.junit.Assert.assertNotNull
import org.junit.Test
import kotlin.test.assertEquals
Expand Down Expand Up @@ -44,7 +43,7 @@ class DslTest {
assertTrue(module.nullToEmptyCollection)
assertTrue(module.nullToEmptyMap)
assertTrue(module.nullIsSameAsDefault)
assertEquals(module.singletonSupport, CANONICALIZE)
assertTrue(module.enabledSingletonSupport)
assertTrue(module.strictNullChecks)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class KotlinModuleTest {
assertFalse(module.nullToEmptyCollection)
assertFalse(module.nullToEmptyMap)
assertFalse(module.nullIsSameAsDefault)
assertEquals(SingletonSupport.DISABLED, module.singletonSupport)
assertFalse(module.enabledSingletonSupport)
assertFalse(module.strictNullChecks)
assertFalse(module.kotlinPropertyNameAsImplicitName)
Expand All @@ -41,7 +40,6 @@ class KotlinModuleTest {
assertTrue(module.nullToEmptyCollection)
assertTrue(module.nullToEmptyMap)
assertTrue(module.nullIsSameAsDefault)
assertEquals(SingletonSupport.CANONICALIZE, module.singletonSupport)
assertTrue(module.enabledSingletonSupport)
assertTrue(module.strictNullChecks)
assertTrue(module.kotlinPropertyNameAsImplicitName)
Expand Down Expand Up @@ -81,7 +79,7 @@ class KotlinModuleTest {
enable(SingletonSupport)
}.build()

assertEquals(SingletonSupport.CANONICALIZE, module.singletonSupport)
assertTrue(module.enabledSingletonSupport)
}

@Test
Expand Down Expand Up @@ -112,7 +110,7 @@ class KotlinModuleTest {
assertTrue(deserialized.nullToEmptyCollection)
assertTrue(deserialized.nullToEmptyMap)
assertTrue(deserialized.nullIsSameAsDefault)
assertEquals(SingletonSupport.CANONICALIZE, deserialized.singletonSupport)
assertTrue(deserialized.enabledSingletonSupport)
assertTrue(deserialized.strictNullChecks)
}

Expand Down