Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.