I'm using Jackson to deserialize a JSON that could contain null values for Map variables. What I want is if the value is null, I want the map to be an empty HashMap instead of null.
JSON:
{"names":null, "descriptions":null, "nicknames":null...}
Java class:
private User {
private Map<String,String> names = new HashMap<>();
private Map<String,String> descriptions = new HashMap<>();
private Map<String,String> nicknames = new HashMap<>();
}
Right now when the ObjectMapper
deserializes the JSON, it overrides the fields, and sets names
, descriptions
, and nicknames
as null.
Is there a a generic way so I would not have to add code each time I have a new map property?