I want to deserialize an arbitrary JSON into a Map<String, Object>
. The value of this map is either some primitive (such as an Integer
, String
, LocalDate
, ...) or another Map<String, Object>
(recursive).
To get the primitive, some kind of custom client callback should be called for each property. Depending on the key, certain deserialization will happen. For example (pseudo-code):
{
"name": "Bill",
"age": 53,
"timestamp": "2012-04-23T18:25:43.511Z",
"coordinates": "51.507351;-0.127758",
"address": {
"street": "Wallstreet",
"city": "NY"
}
}
Object convert(key, value) {
if ("name".equals(key)) {
return value.toString();
} else if ("timestamp".equals(key)) {
return LocalDate.parse(value);
} else if ("coordinates".equals(key)) {
return Coordinates.parse(value);
}
...
}
In SO Jackson - Recursive parsing into Map<String, Object> a simple generic solution is provided. However, this simply deserializes each non-object property to a String
. Is it possible to add a custom client callback, as shown above, to the deserialization process?