Skip to content

Commit 809af89

Browse files
committed
Merge remote-tracking branch 'origin/2.13' into 2.14
2 parents cf1833f + a528c41 commit 809af89

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

release-notes/CREDITS-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Authors:
1313

1414
Contributors:
1515

16+
Stefan Schmid (schmist@github)
17+
* #519: Contributed test for #518 (null should deserialize to _the_ Unit instance)
18+
1619
wrongwrong (k163377@github)
1720
* #456: Refactor KNAI.findImplicitPropertyName()
1821
* #449: Refactor AnnotatedMethod.hasRequiredMarker()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.fasterxml.jackson.module.kotlin.test.github.failing
2+
3+
import com.fasterxml.jackson.module.kotlin.KotlinFeature.SingletonSupport
4+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
5+
import com.fasterxml.jackson.module.kotlin.jsonMapper
6+
import com.fasterxml.jackson.module.kotlin.kotlinModule
7+
import com.fasterxml.jackson.module.kotlin.readValue
8+
import com.fasterxml.jackson.module.kotlin.test.expectFailure
9+
import kotlin.test.assertSame
10+
import org.junit.Test
11+
12+
/**
13+
* An empty object should be deserialized as *the* Unit instance for a nullable Unit reference Type.
14+
*/
15+
class TestGithub518 {
16+
17+
/**
18+
* Empty object did not serialize to the singleton Unit before 2.13 as described in
19+
* https://github.com/FasterXML/jackson-module-kotlin/issues/196.
20+
*/
21+
@Test
22+
fun deserializeEmptyObjectToSingletonUnit() {
23+
assertSame(jacksonObjectMapper().readValue<Unit>("{}"), Unit)
24+
}
25+
26+
/**
27+
* Empty object does not serialize to the singleton Unit for a nullable reference Type as described in
28+
* https://github.com/FasterXML/jackson-module-kotlin/issues/518.
29+
*/
30+
@Test
31+
fun deserializeEmptyObjectToSingletonUnitFails() {
32+
expectFailure<AssertionError>("GitHub #518 has been fixed!") {
33+
assertSame(jacksonObjectMapper().readValue<Unit?>("{}"), Unit)
34+
}
35+
}
36+
37+
/**
38+
* Empty object serializes to the singleton Unit for a nullable reference if singleton support is enabled. Is this
39+
* setting really required to deserialize Unit correctly or should it also work correctly without singleton support
40+
* enabled?
41+
*/
42+
@Test
43+
fun deserializeEmptyObjectToSingletonUnitWithSingletonSupport() {
44+
val objectMapper = jsonMapper { addModule(kotlinModule { configure(SingletonSupport, true) }) }
45+
assertSame(objectMapper.readValue<Unit?>("{}"), Unit)
46+
}
47+
}

0 commit comments

Comments
 (0)