Jackson: exclude object from serialization based on its properties -


what easiest way in jackson exclude object serialization based on properties?

e.g., instance o of class c has boolean enabled field. if o.enabled == false, object shouldn't serialized.

also, how can make work in conjunction current json view? e.g., instance o of class c has boolean topsecret field. if o.topsecret == true, , if current json view not topsecret.class, object shouldn't serialized.

there no direct functionality doing this, because way serialization works, value objects can not decide if want serialized or not. because property name may have been written, must written value. rather, object properties determine inclusion/exclusion.

with this, json filters (http://www.cowtowncoder.com/blog/archives/2011/09/entry_461.html) perhaps work you. json views static allow level of control.

another possibility try use machinery deals @jsoninclude. jsonserializer has isempty(...) method used check whether object of type serializer handles considered "empty", , possibly excluded serialization. if number of types need handle limited, might work. based on original question not case.

yet possibility two-phase processing: first convert pojos tree model (jsonnode), traverse it, remove whatever should not included. , after this, serialize tree model.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -