I have a class like this:
public class Person {
private String name;
public String getName(){
return name;
}
}
I am using an ObjectMapper configured like this:
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
I have a String str
that contains this { "address" : "something" }
. Note that there is no "name" field in the json. If I do something like this:
mapper.readValue(str, Person.class);
then I actually get back a Person object with name set to null. Is there a way to configure the mapper to throw an exception instead, or return a null reference instead of a Person? I want Jackson to consider missing fields a failure and don't want to do explicit null checks on the resulting object's fields.