Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<T>(val data: T)

val mapper = jacksonObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL)

@Test
fun failing() {
val value = Failing<String?>(null)
val json = mapper.writeValueAsString(value)

assertThrows<InvalidNullException> {
val deserializedValue = mapper.readValue<Failing<String?>>(json)
assertEquals(value ,deserializedValue)
}
}

data class WorkAround<T>(@JsonProperty(isRequired = OptBoolean.FALSE) val data: T)

@Test
fun workAround() {
val value = WorkAround<String?>(null)
val json = mapper.writeValueAsString(value)

val deserializedValue = mapper.readValue<WorkAround<String?>>(json)
assertEquals(value ,deserializedValue)
}
}