FasterXML / jackson-modules-java8

Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)
Apache License 2.0
401 stars 117 forks source link

read absent optional value in empty #91

Closed DVMaslov closed 5 years ago

DVMaslov commented 6 years ago
fun main(args: Array<String>) {
    val mapper = ObjectMapper().apply {
        registerModule(Jdk8Module())
        registerModule(KotlinModule())
    }

    println(mapper.writeValueAsString(SomePatch(null, Optional.empty(), Optional.of("hello"))))
    println(mapper.readValue("{\"y\":null,\"z\":\"hello\"}", SomePatch::class.java))
}

@JsonInclude(JsonInclude.Include.NON_NULL)
data class SomePatch(
        val x: Optional<Int>?,
        val y: Optional<String>?,
        val z: Optional<String>?
)

output for version 2.9.6:

{"y":null,"z":"hello"}
SomePatch(x=null, y=Optional.empty, z=Optional[hello])

output for version 2.9.7:

{"y":null,"z":"hello"}
SomePatch(x=Optional.empty, y=Optional.empty, z=Optional[hello])

x absent in json but deserialize in Optional.empty

cowtowncoder commented 5 years ago

Since this is with Kotlin, I think this belongs under:

https://github.com/FasterXML/jackson-module-kotlin

except that if it can be reproduced with just Java, then here.

DVMaslov commented 5 years ago

https://github.com/FasterXML/jackson-module-kotlin/issues/190