thanksforallthefish
12/29/2021, 4:45 PMvalue class
with jackson?
fun main() {
val string = ObjectMapper().findAndRegisterModules()
.convertValue<Map<String, String>>(Value("any"))
println(string)
}
@JvmInline
value class Value(val value: String)
prints {value=any}
with jackson 2.12.5, but fails with jackson 2.13.0. error is
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `java.util.LinkedHashMap` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('any')
at [Source: UNKNOWN; byte offset: #UNKNOWN]
though https://github.com/FasterXML/jackson-module-kotlin/issues/464 makes me wonder if my expectation is wrong. my use case is the one marked as “broken”:
"broken": [ {"value":0}, {"value":0} ]
, though this is exactly what I wantwrongwrong
12/30/2021, 9:52 AMvalue class
with an unboxed
value in any case.
Custom serializers configured for value class
do not currently work for this use case.
https://github.com/FasterXML/jackson-module-kotlin/issues/524
An attempt to make this work properly is underway in the following PR
https://github.com/FasterXML/jackson-module-kotlin/pull/527
When this PR is merged, I believe it will be possible to make it work as expected by using a custom serializer.
Also, if there is a strong desire to serialize the`toString` form as well as the data class
, an additional option may be introduced in the KotlinModule
.
You can also open an issue on GitHub about this option.