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
If I have a data class with a property defined in the body, deserializing works fine.
If I have a data object with a property defined in the body, deserializing throws an exception when deserializing due to an unrecognized field.
Exception in thread "main" com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "int" (class Second), not marked as ignorable (0 known properties: ])
I think this works fine for classes due to MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS and MapperFeature.INFER_PROPERTY_MUTATORS (both default to true), but with Kotlin objects it doesn't work.
To Reproduce
data classFirst(
valfoo:String,
) {
val int:Int=1
}
data objectSecond {
val int:Int=2
}
funmain() {
val mapper = jacksonObjectMapper()
println(mapper.writeValueAsString(First("bar"))) // {"foo":"bar","int":1}println(mapper.writeValueAsString(Second)) // {"int":2}println(mapper.readValue<First>("{\"foo\":\"bar\",\"int\":1}")) // First(foo=bar)println(mapper.readValue<Second>("{\"int\":2}")) // THROWS!
}
Expected behavior
I expect no exception to be thrown in the above example.
Search before asking
Describe the bug
If I have a
data class
with a property defined in the body, deserializing works fine.If I have a
data object
with a property defined in the body, deserializing throws an exception when deserializing due to an unrecognized field.I think this works fine for classes due to
MapperFeature.ALLOW_FINAL_FIELDS_AS_MUTATORS
andMapperFeature.INFER_PROPERTY_MUTATORS
(both default totrue
), but with Kotlin objects it doesn't work.To Reproduce
Expected behavior
I expect no exception to be thrown in the above example.
Versions
Kotlin: 2.0.0
Jackson-module-kotlin: 2.17.2
Jackson-databind: 2.17.2
Additional context
No response
The text was updated successfully, but these errors were encountered: