Jackson ObjectMapper DeserializationConfig.Feature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT

Note the javadoc of ACCEPT_EMPTY_STRING_AS_NULL_OBJECT

Feature that can be enabled to allow JSON empty String value (“”) to be bound to POJOs as null.

So an empty String can be used to map null to a POJO. A String is not a POJO, it is considered a JSON primitive value.

You cannot use that here.

ACCEPT_EMPTY_STRING_AS_NULL_OBJECT would work for something like

{"name":"First Name","phone":"","unknown":"test"}

Where you would make the TestBean.phone field of some POJO type like

class Phone {
    private String number;
}

Then deserializing would make the phone field be null.

Leave a Comment