-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
This is a shortcoming in jackson-module-kotlin
that I hoped could be fixed by this project.
Consider the mapper
val mapper = ObjectMapper()
.registerKotlinModule()
.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT)
and the class
data class TestData(
val defaulted: Boolean = true
)
When we serialize TestData
where defaulted = false
with this mapper, the field is skipped since the mapper assumes that false
is the default value for a boolean property. However, when the value is deserialized, the default value for the property is used, and this causes a roundtrip failure.
val data = TestData(defaulted = false)
println(data) // TestData(defaulted=false)
println(println(mapper.writeValueAsString(data))) // {}
println(mapper.readValue(mapper.writeValueAsString(data), TestData::class.java)) // TestData(defaulted=true)
Is there any way this new approach with kotlinx-metadata
can be used to determine when a property's value matches the default constructor value and adjust serialization appropriately, or maybe just always include properties when the default is non-standard?
Here is the corresponding issue for jackson-module-kotlin
: FasterXML/jackson-module-kotlin#478