diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 35aa72212..f0506727b 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -21,6 +21,7 @@ Tatu Saloranta (@cowtowncoder) * #889: Upgrade kotlin dep to 1.9.25 (from 1.9.24) WrongWrong (@k163377) +* #930: Add tests for #917 * #929: Bug fixes to hasRequiredMarker and added isRequired considerations * #914: Add test case to serialize Nothing? (for #314) * #910: Add default KeyDeserializer for value class diff --git a/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub917.kt b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub917.kt new file mode 100644 index 000000000..30e46e702 --- /dev/null +++ b/src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/GitHub917.kt @@ -0,0 +1,39 @@ +package com.fasterxml.jackson.module.kotlin.test.github + +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.annotation.JsonProperty +import com.fasterxml.jackson.annotation.OptBoolean +import com.fasterxml.jackson.databind.exc.InvalidNullException +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertThrows +import kotlin.test.assertEquals + +class GitHub917 { + data class Failing(val data: T) + + val mapper = jacksonObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL) + + @Test + fun failing() { + val value = Failing(null) + val json = mapper.writeValueAsString(value) + + assertThrows { + val deserializedValue = mapper.readValue>(json) + assertEquals(value ,deserializedValue) + } + } + + data class WorkAround(@JsonProperty(isRequired = OptBoolean.FALSE) val data: T) + + @Test + fun workAround() { + val value = WorkAround(null) + val json = mapper.writeValueAsString(value) + + val deserializedValue = mapper.readValue>(json) + assertEquals(value ,deserializedValue) + } +}