I have a class defined as below:
// Ignore all the unknown properties in input JSON
@JsonIgnoreProperties(ignoreUnknown = true)
// Only include non null values in deserialized Java object.
@JsonInclude(value = Include.NON_NULL)
public class Person {
@JsonProperty("person_id")
private String personId;
@JsonProperty("school")
private String school;
@JsonProperty("hobbies")
private Map<String, List<AttributeBag>> hobbies = new HashMap<String, List<AttributeBag>>();
@JsonProperty("tasks")
private Map<String, Map<String, AttributeBag>> tasks = new HashMap<String, Map<String, AttributeBag>>();
public Map<String, List<AttributeBag>> getHobbies() {
return hobbies;
}
public Person(String person_id, String school) {
super();
this.person_id = person_id;
this.school = school;
}
When I use a JSON string below to deserialize from string to object,
{
"person_id":"123",
"school":"stanford University"
}
From the object I got deserialized, the hobbies is create but empty, and the tasks is not created even. I am expecting the way like "tasks", if there is no corresponding field in JSON, it SHOULD NOT get deserialized in the object.
But the weird thing is : when I check object.getHobbies()!=null but the tasks part is null. I want both are null in the object if they were not present in JSON.
I have a constructor for the Person class but I did not initialize both hobbies and tasks part.
Thanks a lot