I would like to make use of extra deserializers defined for Kotlin-specific data types: UInt, ULong and UShort.
The following code does work as expected:
val actual: UInt = objectMapper.readValue("4294967295")
val expected: UInt = 4294967295u
assertThat(actual).isEqualTo(expected)
However I can't make it work for a data class like this:
data class U(
@JsonProperty("x")
@JsonDeserialize(using = UIntDeserializer::class)
val x: UInt
)
val actual: U = objectMapper.readValue("""{"x":4294967295}""")
// val expected: U(4294967295u)
// assertThat(actual).isEqualTo(expected)
readValue fails with the following diagnostics:
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)
...
If I adjust type of x to Int, everything works as expected (but obviously it can't handle the upper half of integer values anymore).
Of course, the project has the whole bunch of Jackson modules including jackson-module-kotlin plugged in.
So the question is: how to properly configure the Object Mapper to handle data classes with Kotlin-specific integer types.