java - JsonIgnore not working -
this question has answer here:
- jackson: how prevent field serialization 6 answers
i trying make these properties don't serialized, reason no matter still getting serialized , sent down client. have tried using @jsonignoreproperties({"dobefore","doafter","doaftercomplete"})
, have tried using @jsonignore
on getters, , have tried both , doesn't seem make difference. here's class looks like:
@jsonignoreproperties({"dobefore","doafter","doaftercomplete"}) public class action { //for reordering actions default actions private string dobefore; private string doafter; private string doaftercomplete; private string eventid; private list<actionargument> arguments; //action perform when action done private list<action> oncompleteactions; public action() {} public action(string eventid, list<actionargument> arguments, list<action> oncompleteactions) { this.eventid = eventid; this.arguments = arguments; this.oncompleteactions = oncompleteactions; } public string geteventid() { return eventid; } public void seteventid(string eventid) { this.eventid = eventid; } public list<actionargument> getarguments() { return arguments; } public void setarguments(list<actionargument> arguments) { this.arguments = arguments; } public list<action> getoncompleteactions() { return oncompleteactions; } public void setoncompleteactions(list<action> oncompleteactions) { this.oncompleteactions = oncompleteactions; } @jsonignore public string getdobefore() { return dobefore; } public void setdobefore(string dobefore) { this.dobefore = dobefore; } @jsonignore public string getdoafter() { return doafter; } public void setdoafter(string doafter) { this.doafter = doafter; } @jsonignore public string getdoaftercomplete() { return doaftercomplete; } public void setdoaftercomplete(string doaftercomplete) { this.doaftercomplete = doaftercomplete; } }
you can use @jsonignore
on each getter , setter. seems easier see ones ignored. plus can have property ignored serialization , not ignored deserialization. (that assume remote client isn't using same code, doesn't it.)
it works me jersey/jackson. jaxrs framework using?
for jersey, need section in web.xml file:
<servlet> <servlet-name>myjaxrsservlet</servlet-name> <servlet-class>com.sun.jersey.spi.container.servlet.servletcontainer</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.mycompany.transformation</param-value> </init-param> <init-param> <param-name>com.sun.jersey.api.json.pojomappingfeature</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet>
this tell scan packages com.mycompany.transformation.**
annotations.
Comments
Post a Comment