java - Jackson custom serialization getter -
java - Jackson custom serialization getter -
let's have pojo like:
public class user { private long id; private string username; // usual getters , setters .... // serialisation purposes public string getupperusername() { homecoming this.id % 2 == 0 ? username : username.touppercase(); } } i create conditional serializer serialises different value actual 1 if conditions satisfied.
i looked @ @jsongetter apparently it's deprecated, @jsonproperty doesn't seem work.
do have idea?
thank in advance :)
you seek write custom serializer implementing jsonserializer , using @jsonserialize then: http://www.baeldung.com/jackson-custom-serialization seems overkill.
also, if acceptable, seek set logic of getupperusername() in usual getter.
ps: unusual @jsonproperty not work, match here.
java json jackson
Comments
Post a Comment