java - Jackson @JsonProperty(required=true) doesn't throw an exception -


i using jackson 2.2 annotation @jsonproperty required set true. while deserializing json file doesn't contain property via objectmapper readvalue() method no exception being thrown. supposed work in different way or did missed something?

my dto class:

public class user {     public enum gender {male, female}      ;      public static class name {         private string _first, _last;          public string getfirst() {             return _first;         }          public string getlast() {             return _last;         }          public void setfirst(string s) {             _first = s;         }          public void setlast(string s) {             _last = s;         }     }      private gender _gender;     private name _name;     private boolean _isverified;     private byte[] _userimage;      @jsonproperty(value ="naame",required = true)     public name getname() {         return _name;     }      @jsonproperty("verified")     public boolean isverified() {         return _isverified;     }      @jsonproperty("gender")     public gender getgender() {         return _gender;     }     @jsonproperty("img")     public byte[] getuserimage() {         return _userimage;     }      @jsonproperty(value ="naame",required = true)     public void setname(name n) {         _name = n;     }     @jsonproperty("verified")     public void setverified(boolean b) {         _isverified = b;     }     @jsonproperty("gender")     public void setgender(gender g) {         _gender = g;     }     @jsonproperty("img")     public void setuserimage(byte[] b) {         _userimage = b;     } } 

this how deserialize class:

public class serializer {     private objectmapper mapper;      public serializer() {         mapper = new objectmapper();         simplemodule sm = new simplemodule("pif deserialization");         mapper.registermodule(sm);     }      public void writeuser(file filename, user user) throws ioexception {         mapper.writevalue(filename, user);     }      public user readuser(file filename) throws ioexception {           return mapper.readvalue(filename, user.class);       } } 

this how called:

    serializer serializer = new serializer();     user result = serializer.readuser(new file("user.json")); 

actuall json looks like:

{"gender":"female","verified":true,"img":"aq8="} 

i expect since _name not specified in json file , required exception thrown.

as per jackson annotations javadocs: "note of 2.0, property not used beandeserializer: support expected added later minor version."

that is: no validation performed using settings. (currently) used generating json schema, or custom code.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -