Yonatan Karp-Rudin
12/11/2023, 9:13 AM1.7.x
to version 1.8.x
or above because of serialization value classes inside of a data class.
Let's consider the following example:
@JvmInline
value class Value(val i: Int)
data class Data(val j: Value)
data class Wrapper(val value: Value, val data: Data)
When trying the following code:
val objectMapper = jacksonObjectMapper()
.setPropertyNamingStrategy(PropertyNamingStrategies.SnakeCaseStrategy())
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
.registerModule(JavaTimeModule())
val json = """{"i":1,"j":771}"""
val deserialized = objectMapper.readValue<Wrapper>(json)
This code execution ends up with the following error: (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
.
This can be resolved by adding an empty constructor to the classes, but it makes very little sense, and I'm afraid that it would be abused by other developers in the codebase... is there any alternative that I can use here to solve the issue?Yonatan Karp-Rudin
12/11/2023, 11:07 AM