-
-
Notifications
You must be signed in to change notification settings - Fork 180
Description
Your question
When upgrading from Jackson 2.17.2 to 2.18.2, I encountered an issue with deserializing a custom wrapper class (ValidatedList) directly from an array in JSON. Previously, in 2.17.2, the deserialization worked as expected.
Here is the code representation of my classes:
data class Profile(
val name: String,
val list: ValidatedList<Record>,
)
class ValidatedList<Record>(vararg list: Record) {
var items: List<Record> = listOf()
init {
this.items = list.asList()
}
}
data class Record(
val nationality: String,
val firstName: String,
)
In Jackson 2.17.2, the following JSON deserialized correctly:
{
"name": "JohnDoe",
"list": [
{
"nationality": "US",
"firstName": "John"
},
{
"nationality": "GB",
"firstName": "Jane"
}
]
}
But in 2.18.2 i have a problem with deserialization:
Error: Cannot deserialize value of type `example.ValidatedList<example.Record>` from Array value (token `JsonToken.START_ARRAY`) at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 3, column: 11] (through reference chain: example.Profile["list"])
To make the deserialization work in 2.18.2, the JSON has to be structured with an additional items key like this:
{
"name": "JohnDoe",
"list": {
"items": [
{
"nationality": "US",
"firstName": "John"
},
{
"nationality": "GB",
"firstName": "Jane"
}
]
}
}
Question
Is there a way to configure Jackson 2.18.2 to accept the original JSON format (without the nested items key)? I would like to maintain compatibility with the original JSON format while using the newer version of Jackson.
Any advice or configuration suggestions to address this would be greatly appreciated