Skip to content

Commit

Permalink
Merge pull request #751 from k163377/fix-prop-name
Browse files Browse the repository at this point in the history
Marked useKotlinPropertyNameForGetter as deprecated.
  • Loading branch information
k163377 authored Dec 31, 2023
2 parents 452cc57 + 2cc4589 commit b2be4ae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 26 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 @@ -53,9 +53,17 @@ class KotlinModule @Deprecated(
val nullIsSameAsDefault: Boolean = NullIsSameAsDefault.enabledByDefault,
val singletonSupport: SingletonSupport = DISABLED,
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
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
package com.fasterxml.jackson.module.kotlin

import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinFeature.NullIsSameAsDefault
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 com.fasterxml.jackson.module.kotlin.SingletonSupport.DISABLED
import com.fasterxml.jackson.module.kotlin.KotlinFeature.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
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 @@ -38,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 @@ -51,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 @@ -94,7 +79,7 @@ class KotlinModuleTest {
enable(SingletonSupport)
}.build()

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

@Test
Expand Down Expand Up @@ -125,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 b2be4ae

Please sign in to comment.