Skip to content

Commit

Permalink
Merge remote-tracking branch 'FasterXML/2.17'
Browse files Browse the repository at this point in the history
  • Loading branch information
k163377 committed Dec 31, 2023
2 parents f125d7d + b2be4ae commit f663f08
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Contributors:
# 2.17.0 (not yet released)

WrongWrong (@k163377)
* #751: Marked useKotlinPropertyNameForGetter as deprecated.
* #747: Improved performance related to KotlinModule initialization and setupModule.
* #746: The KotlinModule#serialVersionUID is set to private.
* #745: Modified isKotlinClass determination method.
Expand Down
2 changes: 2 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Co-maintainers:

2.17.0 (not yet released)

#751: The KotlinModule#useKotlinPropertyNameForGetter property was deprecated because it differed from the name of the KotlinFeature.
Please use KotlinModule#kotlinPropertyNameAsImplicitName from now on.
#747: Improved performance related to KotlinModule initialization and setupModule.
With this change, the KotlinModule initialization error when using Kotlin 1.4 or lower has been eliminated.
#746: The KotlinModule#serialVersionUID is set to private.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.util.BitSet
/**
* @see KotlinModule.Builder
*/
enum class KotlinFeature(private val enabledByDefault: Boolean) {
enum class KotlinFeature(internal val enabledByDefault: Boolean) {
/**
* This feature represents whether to deserialize `null` values for collection properties as empty collections.
*/
Expand Down
28 changes: 20 additions & 8 deletions src/main/kotlin/tools/jackson/module/kotlin/KotlinModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,23 @@ class KotlinModule @Deprecated(
"tools.jackson.module.kotlin.KotlinFeature"
)
) constructor(
val reflectionCacheSize: Int = 512,
val nullToEmptyCollection: Boolean = false,
val nullToEmptyMap: Boolean = false,
val nullIsSameAsDefault: Boolean = false,
val reflectionCacheSize: Int = Builder.DEFAULT_CACHE_SIZE,
val nullToEmptyCollection: Boolean = NullToEmptyCollection.enabledByDefault,
val nullToEmptyMap: Boolean = NullToEmptyMap.enabledByDefault,
val nullIsSameAsDefault: Boolean = NullIsSameAsDefault.enabledByDefault,
val singletonSupport: SingletonSupport = DISABLED,
val strictNullChecks: Boolean = false,
val useKotlinPropertyNameForGetter: Boolean = false,
val useJavaDurationConversion: Boolean = false,
val strictNullChecks: Boolean = StrictNullChecks.enabledByDefault,
@Deprecated(
level = DeprecationLevel.WARNING,
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) {
val kotlinPropertyNameAsImplicitName: Boolean get() = useKotlinPropertyNameForGetter

companion object {
// Increment when option is added
private const val serialVersionUID = 2L
Expand Down Expand Up @@ -151,7 +159,11 @@ class KotlinModule @Deprecated(
}

class Builder {
var reflectionCacheSize: Int = 512
companion object {
internal const val DEFAULT_CACHE_SIZE = 512
}

var reflectionCacheSize: Int = DEFAULT_CACHE_SIZE
private set

private val bitSet: BitSet = KotlinFeature.defaults
Expand Down
38 changes: 11 additions & 27 deletions src/test/kotlin/tools/jackson/module/kotlin/KotlinModuleTest.kt
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
package tools.jackson.module.kotlin

import tools.jackson.module.kotlin.KotlinFeature.NullIsSameAsDefault
import tools.jackson.module.kotlin.KotlinFeature.NullToEmptyCollection
import tools.jackson.module.kotlin.KotlinFeature.NullToEmptyMap
import tools.jackson.module.kotlin.KotlinFeature.SingletonSupport
import tools.jackson.module.kotlin.KotlinFeature.StrictNullChecks
import tools.jackson.module.kotlin.SingletonSupport.CANONICALIZE
import tools.jackson.module.kotlin.SingletonSupport.DISABLED
import tools.jackson.module.kotlin.KotlinFeature.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import tools.jackson.databind.ObjectMapper
import tools.jackson.databind.json.JsonMapper
import kotlin.test.assertNotNull

class KotlinModuleTest {
/**
* Ensure that the default Builder matches Feature default settings.
*/
@Test
fun builderDefaultsMatchFeatures() {
val module = KotlinModule.Builder().build()

assertEquals(module.reflectionCacheSize, 512)
assertFalse(module.nullToEmptyCollection)
assertFalse(module.nullToEmptyMap)
assertFalse(module.nullIsSameAsDefault)
assertEquals(module.singletonSupport, DISABLED)
assertFalse(module.strictNullChecks)
}

@Test
fun builder_Defaults() {
val module = KotlinModule.Builder().build()
Expand All @@ -39,8 +17,10 @@ class KotlinModuleTest {
assertFalse(module.nullToEmptyCollection)
assertFalse(module.nullToEmptyMap)
assertFalse(module.nullIsSameAsDefault)
assertEquals(DISABLED, module.singletonSupport)
assertEquals(SingletonSupport.DISABLED, module.singletonSupport)
assertFalse(module.strictNullChecks)
assertFalse(module.kotlinPropertyNameAsImplicitName)
assertFalse(module.useJavaDurationConversion)
}

@Test
Expand All @@ -52,14 +32,18 @@ class KotlinModuleTest {
enable(NullIsSameAsDefault)
enable(SingletonSupport)
enable(StrictNullChecks)
enable(KotlinPropertyNameAsImplicitName)
enable(UseJavaDurationConversion)
}.build()

assertEquals(123, module.reflectionCacheSize)
assertTrue(module.nullToEmptyCollection)
assertTrue(module.nullToEmptyMap)
assertTrue(module.nullIsSameAsDefault)
assertEquals(CANONICALIZE, module.singletonSupport)
assertEquals(SingletonSupport.CANONICALIZE, module.singletonSupport)
assertTrue(module.strictNullChecks)
assertTrue(module.kotlinPropertyNameAsImplicitName)
assertTrue(module.useJavaDurationConversion)
}

@Test
Expand Down Expand Up @@ -95,7 +79,7 @@ class KotlinModuleTest {
enable(SingletonSupport)
}.build()

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

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

Expand Down

0 comments on commit f663f08

Please sign in to comment.