Skip to content

Commit 73f5bef

Browse files
authored
Merge pull request #936 from k163377/change-defaults
Change of default settings for 3.0
2 parents f4ed260 + 3614ec2 commit 73f5bef

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

release-notes/CREDITS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ Authors:
1717

1818
Contributors:
1919

20+
# 3.0.0-rc2 (not yet released)
21+
22+
WrongWrong (@k163377)
23+
* #936: Change of default settings for 3.0
24+
25+
# 3.0.0-rc1 (07-Mar-2025)
26+
2027
hokita
2128
* #702: Fix outdated link in master branch README
2229

release-notes/VERSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ Former maintainers:
2222
=== Releases ===
2323
------------------------------------------------------------------------
2424

25+
3.0.0-rc2 (not yet released)
26+
#936: `StrictNullChecks` and `SingletonSupport` are now enabled by default
27+
2528
3.0.0-rc1 (07-Mar-2025)
2629

2730
- Minimum Java baseline: Java 17

src/main/kotlin/tools/jackson/module/kotlin/KotlinFeature.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@ enum class KotlinFeature(internal val enabledByDefault: Boolean) {
2525
NullIsSameAsDefault(enabledByDefault = false),
2626

2727
/**
28-
* By default, there's no special handling of singletons (pre-2.10 behavior).
29-
* Each time a Singleton object is deserialized a new instance is created.
30-
*
31-
* When this feature is enabled, it will deserialize then canonicalize (was the default in 2.10).
28+
* When this feature is enabled, it will deserialize then canonicalize.
3229
* Deserializing a singleton overwrites the value of the single instance.
3330
*
31+
* The 2.x default was disabled, and a new instance was created each time a singleton object was deserialized.
32+
*
3433
* See [jackson-module-kotlin#225]: keep Kotlin singletons as singletons.
3534
*/
36-
SingletonSupport(enabledByDefault = false),
35+
SingletonSupport(enabledByDefault = true),
3736

3837
/**
3938
* This feature represents whether to check deserialized collections.
@@ -88,8 +87,10 @@ enum class KotlinFeature(internal val enabledByDefault: Boolean) {
8887
* This is a temporary option for a phased backend migration,
8988
* which will eventually be merged into [StrictNullChecks].
9089
* Also, specifying both this and [StrictNullChecks] is not permitted.
90+
*
91+
* Since 3.0, this option is enabled by default.
9192
*/
92-
NewStrictNullChecks(enabledByDefault = false);
93+
NewStrictNullChecks(enabledByDefault = true);
9394

9495
internal val bitSet: BitSet = (1 shl ordinal).toBitSet()
9596

src/test/kotlin/tools/jackson/module/kotlin/KotlinModuleTest.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ class KotlinModuleTest {
1313
// After the final migration is complete, this test will be removed.
1414
@Test
1515
fun strictNullChecksTests() {
16-
assertTrue(kotlinModule { enable(StrictNullChecks) }.strictNullChecks)
16+
assertTrue(
17+
kotlinModule {
18+
disable(NewStrictNullChecks)
19+
enable(StrictNullChecks)
20+
}.strictNullChecks
21+
)
1722
assertTrue(kotlinModule { enable(NewStrictNullChecks) }.strictNullChecks)
1823

1924
assertThrows<IllegalArgumentException> {
@@ -32,8 +37,8 @@ class KotlinModuleTest {
3237
assertFalse(module.nullToEmptyCollection)
3338
assertFalse(module.nullToEmptyMap)
3439
assertFalse(module.nullIsSameAsDefault)
35-
assertFalse(module.singletonSupport)
36-
assertFalse(module.strictNullChecks)
40+
assertTrue(module.singletonSupport)
41+
assertTrue(module.strictNullChecks)
3742
assertFalse(module.kotlinPropertyNameAsImplicitName)
3843
assertFalse(module.useJavaDurationConversion)
3944
}

src/test/kotlin/tools/jackson/module/kotlin/test/github/Github27.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import org.junit.jupiter.api.Assertions
99
import org.junit.jupiter.api.Assertions.assertEquals
1010
import org.junit.jupiter.api.Test
1111
import tools.jackson.databind.DeserializationFeature
12+
import tools.jackson.module.kotlin.KotlinFeature
1213
import kotlin.test.assertTrue
1314
import kotlin.test.fail
1415

1516
class TestGithub27 {
16-
val mapper = jacksonMapperBuilder().disable(SerializationFeature.INDENT_OUTPUT)
17-
.build()
17+
val mapper = jacksonMapperBuilder { disable(KotlinFeature.NewStrictNullChecks) }
18+
.disable(SerializationFeature.INDENT_OUTPUT)
19+
.build()
1820

1921
private data class ClassWithNullableInt(val sample: Int?)
2022

src/test/kotlin/tools/jackson/module/kotlin/test/github/failing/Github518.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import tools.jackson.module.kotlin.readValue
88
import tools.jackson.module.kotlin.test.expectFailure
99
import kotlin.test.assertSame
1010
import org.junit.jupiter.api.Test
11+
import tools.jackson.module.kotlin.KotlinFeature
1112

1213
/**
1314
* An empty object should be deserialized as *the* Unit instance for a nullable Unit reference Type.
@@ -30,7 +31,7 @@ class TestGithub518 {
3031
@Test
3132
fun deserializeEmptyObjectToSingletonUnitFails() {
3233
expectFailure<AssertionError>("GitHub #518 has been fixed!") {
33-
assertSame(jacksonObjectMapper().readValue<Unit?>("{}"), Unit)
34+
assertSame(jacksonObjectMapper { disable(SingletonSupport) }.readValue<Unit?>("{}"), Unit)
3435
}
3536
}
3637

0 commit comments

Comments
 (0)