I have requirement where we are calling an api and deserializing the json response into an object using Java. I am using jackson library to do so. There are 2 things needed:
I know how to deserialize json with missing field by simply marking object mapper to ignore missing fields or on class level but how can we achive capturing of these missing fields?
In your mapper use
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
In your pojo, add a field like below. This map will have all ignored properties after deserialization.
@JsonAnyGetter
@JsonAnySetter
Map<String, Object> ignoredProperties = new LinkedHashMap<>();