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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -