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 searched in the issues and found nothing similar.
I searched in the issues of databind and other modules used and found nothing similar.
I have confirmed that the problem only occurs when using Kotlin.
Describe the bug
When deserializing a Kotlin data class from an external JAR using objectMapper.readerWithView(), KotlinModule fails with the following error: Caused by: com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class io.github.cooperlyt.erp.api.data.stock.StockFreezeStatusMessage] value failed for JSON property tenant due to missing (therefore NULL) value for creator parameter tenant which is a non-nullable type at [Source: (String)"{"businessId":1336493025009664,"tenant":"first","type":"LEASE","success":false}"; line: 1, column: 79] (through reference chain: io.github.cooperlyt.erp.api.data.stock.StockFreezeStatusMessage["tenant"])
However, using objectMapper.readValue() works perfectly for the same class and JSON. This issue only occurs when the class is in an external JAR and when using readerWithView() in combination with forType().
Create a Kotlin data class inside a separate project, package it into a JAR, and include it as a dependency in the main project.
Register KotlinModule in the main project using:
val objectMapper =ObjectMapper().registerModule(KotlinModule())
Use readValue() for deserialization (this works fine):
val json ="""{"businessId":1336504106360835,"tenant":"first","type":"LEASE","success":false}"""val value = objectMapper.readValue(json, StockFreezeStatusMessage::class.java)
Now use readerWithView() for deserialization (this throws an exception):
val view:Class<*> =StockFreezeStatusMessage::class.java
val javaType:JavaType= objectMapper.constructType(object:TypeReference<StockFreezeStatusMessage>() {})
val value = objectMapper.readerWithView(view).forType(javaType).readValue<Any>(json)
The second deserialization fails with MissingKotlinParameterException indicating that a non-nullable field (tenant) is missing, even though the JSON contains the correct value.
Moving the data class into the main project (instead of keeping it in the external JAR) this works fine (only Jackson-module-kotlin: 2.18.0-rc1).
Expected behavior
Both readValue() and readerWithView() should correctly deserialize the JSON into the Kotlin data class regardless of whether the class is in the main project or in an external JAR.
Search before asking
Describe the bug
When deserializing a Kotlin data class from an external JAR using objectMapper.readerWithView(), KotlinModule fails with the following error:
Caused by: com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class io.github.cooperlyt.erp.api.data.stock.StockFreezeStatusMessage] value failed for JSON property tenant due to missing (therefore NULL) value for creator parameter tenant which is a non-nullable type at [Source: (String)"{"businessId":1336493025009664,"tenant":"first","type":"LEASE","success":false}"; line: 1, column: 79] (through reference chain: io.github.cooperlyt.erp.api.data.stock.StockFreezeStatusMessage["tenant"])
However, using objectMapper.readValue() works perfectly for the same class and JSON. This issue only occurs when the class is in an external JAR and when using readerWithView() in combination with forType().
To Reproduce
Expected behavior
Both readValue() and readerWithView() should correctly deserialize the JSON into the Kotlin data class regardless of whether the class is in the main project or in an external JAR.
Versions
Kotlin:
Jackson-module-kotlin: 2.15.4
Jackson-databind: 2.15.4
Additional context
No response
The text was updated successfully, but these errors were encountered: