Skip to content

Commit ace591c

Browse files
authored
Merge pull request #319 from ProjectMapK/required-4
Porting tests
2 parents df0c9b4 + 44f9e70 commit ace591c

File tree

1 file changed

+39
-0
lines changed
  • src/test/kotlin/io/github/projectmapk/jackson/module/kogera/zPorted/test/github

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.github.projectmapk.jackson.module.kogera.zPorted.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 io.github.projectmapk.jackson.module.kogera.jacksonObjectMapper
8+
import io.github.projectmapk.jackson.module.kogera.readValue
9+
import org.junit.jupiter.api.Assertions.assertEquals
10+
import org.junit.jupiter.api.Test
11+
import org.junit.jupiter.api.assertThrows
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)