Given the following example JSON:
{
"aud": "you",
"exp": 1300819380,
"user": {
"name": "Joe",
"address": {
"street": "1234 Main Street",
"city": "Anytown",
"state": "CA",
"postalCode": 94401
}
}
}
and the Java interface:
public interface Deserializer {
Map<String,Object> deserialize(String json);
}
Using Jackson, how do I implement deserialize
such that it returns a map of name/value pairs, but converts just the user
field into a Java User
domain object such that the following is possible:
Map<String,Object> map = deserializer.deserialize(json);
assert map.get("user") instanceof User;
The idea is that the top-level name/value pairs can be anything and are unstructured and we don't want to force a domain model. But if a user
member exists, we do want that member value to be unmarshalled into a User
domain instance.
Additionally, if possible, I really don't want to have to modify the deserialize
implementation if the User
domain model changes (e.g. if a field is added or removed over time).