Hi I have the following object mapper:
public <T> T convertJSONtoPOJO(String inputJSON,
Class<T> valueType) throws Exception {
try {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true);
return objectMapper.readValue(inputJSON, valueType);
} catch (Exception exception) {
//my exception which doesnt matter now
}
}
And incoming JSON:
{
"propertyA": "1",
"propertyB": null,
}
And POJO:
@FieldDefaults(level = AccessLevel.PRIVATE)
@Data
public class MyClazz {
String propertyA;
String propertyB;
String propertyC;
}
By default @JsonProperty required is set to false on all of them.
Now while deserializing I want to obtain POJO which does NOT include: a) non-required variables if they do NOT occur in JSON b) variables which have null value.
Currently my code does NOT fail, it simply gives me the following POJO:
propertyA = 1
propertyB = null
propertyC = null
But I want to obtain POJO with only:
propertyA = 1