You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to ask how to properly configure an ObjectMapper to make it capable of deserializing data classes with kotlin-specific integer fields.
Out of the box it works e.g. with raw UInts:
val actual: UInt = objectMapper.readValue("4294967295")
val expected: UInt = 4294967295u
assertThat(actual).isEqualTo(expected)
However, a simple data class like this
data class U(
@JsonProperty("x") // no matter if this annotation exists or not
@JsonDeserialize(using = UIntDeserializer::class) // no matter if this annotation exists or not
val x: UInt
)
val actual: U = objectMapper.readValue("""{"x":4294967295}""")
// val expected: U(4294967295u)
// assertThat(actual).isEqualTo(expected)
The error message is:
Cannot construct instance of `U` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (String)"{"x":4294967295}"; line: 1, column: 2]
com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `U` (although at least one Creator exists): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (String)"{"x":4294967295}"; line: 1, column: 2]
at app//com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:63)
at app//com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1728)
...
Changing the type of x to Int lets it work as expected (obviously, the upper half of an integer values can not be handled).
So the question is how to properly configure ObjectMapper to handle these cases.
jackson-2.13.3 (the version comes from Spring Boot 2.7.0 BOM)
The text was updated successfully, but these errors were encountered:
I would like to ask how to properly configure an ObjectMapper to make it capable of deserializing data classes with kotlin-specific integer fields.
Out of the box it works e.g. with raw
UInt
s:However, a simple data class like this
The error message is:
Changing the type of
x
toInt
lets it work as expected (obviously, the upper half of an integer values can not be handled).So the question is how to properly configure ObjectMapper to handle these cases.
jackson-2.13.3 (the version comes from Spring Boot 2.7.0 BOM)
The text was updated successfully, but these errors were encountered: