hello :wave: has anyone tried `value class` with ...
# jackson-kotlin
t
hello đź‘‹ has anyone tried
value class
with jackson?
Copy code
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
Copy code
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 want
w
The policy is to serialize the
value 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.
690 Views