Skip to content

Commit 76ec01c

Browse files
authored
Merge pull request #930 from k163377/917-wa
Add tests for #917
2 parents 819f4b2 + 72a0f18 commit 76ec01c

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

release-notes/CREDITS-2.x

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Tatu Saloranta (@cowtowncoder)
2121
* #889: Upgrade kotlin dep to 1.9.25 (from 1.9.24)
2222

2323
WrongWrong (@k163377)
24+
* #930: Add tests for #917
2425
* #929: Bug fixes to hasRequiredMarker and added isRequired considerations
2526
* #914: Add test case to serialize Nothing? (for #314)
2627
* #910: Add default KeyDeserializer for value class
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fasterxml.jackson.module.kotlin.test.github
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude
4+
import com.fasterxml.jackson.annotation.JsonProperty
5+
import com.fasterxml.jackson.annotation.OptBoolean
6+
import com.fasterxml.jackson.databind.exc.InvalidNullException
7+
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
8+
import com.fasterxml.jackson.module.kotlin.readValue
9+
import org.junit.jupiter.api.Test
10+
import org.junit.jupiter.api.assertThrows
11+
import kotlin.test.assertEquals
12+
13+
class GitHub917 {
14+
data class Failing<T>(val data: T)
15+
16+
val mapper = jacksonObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)
17+
18+
@Test
19+
fun failing() {
20+
val value = Failing<String?>(null)
21+
val json = mapper.writeValueAsString(value)
22+
23+
assertThrows<InvalidNullException> {
24+
val deserializedValue = mapper.readValue<Failing<String?>>(json)
25+
assertEquals(value ,deserializedValue)
26+
}
27+
}
28+
29+
data class WorkAround<T>(@JsonProperty(isRequired = OptBoolean.FALSE) val data: T)
30+
31+
@Test
32+
fun workAround() {
33+
val value = WorkAround<String?>(null)
34+
val json = mapper.writeValueAsString(value)
35+
36+
val deserializedValue = mapper.readValue<WorkAround<String?>>(json)
37+
assertEquals(value ,deserializedValue)
38+
}
39+
}

0 commit comments

Comments
 (0)