In my JSON I have an element with the following contents:
{
...
"locations": [
[
{
"location_type": "permanent",
"position": "at",
"accuracy": "exact"
},
"and",
{
"location_type": "permanent",
"position": "in",
"accuracy": "exact"
}
],
"or",
{
"location_type": "temporary",
"position": "at",
"accuracy": "exact"
}
],
...
}
As shown, an element of locations
can be:
- a location
- a logical operator
- a list of locations (allowing for complex locations)
I'm getting "Cannot deserialize instance of com.example.processor.transformation.json.Location
out of START_ARRAY token".
How can I consume this into a data structure using Jackson?
What I tried so far:
- Providing a
Location(String logicalOperator)
constructor helps for a flat list case. (I basically turn the operator into a special value ofLocation
.) - Adding a
Location(List<Location> subLocations)
or aLocation(Location[] subLocations)
constructor doesn't help for this case.
Note: I am not in control of the JSON format so I cannot encode it in a more Jackson-friendly way.