I am trying to convert java object to JSON object in Tomcat/jersey using Jackson. And want to suppress serialization(write) of certain properties dynamically.
I can
I don't see any way of doing that. If you need to dynamically decide which properties are marshalled, then I suggest you manually construct a Map
of keys to values for your objects, and then pass that Map
to Jackson, rather than passing the User
object directly.
Yes, JSON View is the way to go.
If you e.g. need to let the client to decide which fields to marshal, this example might help: http://svn.codehaus.org/jackson/tags/1.6/1.6.3/src/sample/CustomSerializationView.java
Check
ObjectMapper.configure(SerialiationJson.Feature f, boolean value)
and
org.codehaus.jackson.annotate.JsonIgnore
annotation
This will work only when you want all instances of a certain type to ignore id on serialization. If you truly want dynamic (aka per instance customization) you will probabily have to hack the jackson library yourself.
Have you tried using JSON Views? Views allow annotation-based mechanism for defining different profiles, so if you just need slightly differing views for different users, this could work for you.