Let's say I have a class like this:
public static class Test {
private Optional<String> something;
public Optional<String> getSomething() {
return something;
}
public void setSomething(Optional<String> something) {
this.something = something;
}
}
If I deserialize this JSON, I get an empty Optional:
{"something":null}
But if property is missing (in this case just empty JSON), I get null instead of Optional<T>
. I could initialize fields by myself of course, but I think it would be better to have one mechanism for null
and missing properties. So is there a way to make jackson deserialize missing properties as empty Optional<T>
?