java - Jackson. Deserialize missing properties as empty Optional -
let's have class 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 deserialize json, empty optional:
{"something":null}
but if property missing(in case empty json), null instead of optional. initialize fields myself of course, think better have 1 mechanism null , missing properties. there way make jackson deserialize missing properties empty optional?
optional not meant used field more return value. why not have:
public static class test { private string something; public optional<string> getsomething() { return optional.ofnullable(something); } public void setsomething(string something) { this.something = something; } }
Comments
Post a Comment