java - Jackson object mapper how to ignore JsonProperty annotation? -
i have following scenario:
public class { @jsonproperty("member") private int member; } public class b { private int member; } now, wish following:
objectmapper mapper = new objectmapper(); b b = new b(); b.setmember("1"); a = mapper.convervalue(b, a.class); ordinarily, work. however, since objectmapper takes annotations such @jsonproperty account, following result:
a.getmember(); // member = null there workaround, fields expected null due set manually, i.e. a.setmember(b.getmember());, defeats purpose of using objectmapper in first place , potentially error-prone.
is there way configure objectmapper ignore @jsonproperty fields of given class (or globally)?
you can configure objectmapper ignore annotations @jsonproperty doing:
objectmapper objectmapper = new objectmapper().configure( org.codehaus.jackson.map.deserializationconfig.feature.use_annotations, false) .configure(org.codehaus.jackson.map.serializationconfig.feature.use_annotations, false) but cause ignore things @jsonignore etc. i'm not aware of way make objectmapper ignore specific annotations.
Comments
Post a Comment