tags:

views:

640

answers:

2

Say I have objects such as a Business with a List of Address objects, and an Order that has a Business.

Is it possible to configure so that when the Order is serialized it excludes the list of addresses from the Business object, and when the business is serialized it includes the list?

I'm using ajax to pull data for an RIA and when working with the Order I don't really care about the address data, but when dealing with Business I do want the list.

I'm also using Hibernate for persistence so this is really an efficiency and performance optimization.

+1  A: 

You could use the JsonIgnore Annotation to ignore the Address list in serialization and switch off the use of annotations in the ObjectMapper's SerializationConfig when serializing a Business. Of course, this means that other annotations you might use are ignored as well. Not perfect, but you might find a better solution looking into this, hope it helps (obviously).

ObjectMapper mapper = new ObjectMapper();
mapper.getSerializationConfig().disable(Feature.USE_ANNOTATIONS);
Wolfram
+2  A: 

If I understand question correctly, yes, I think JSON Views for Jackson would allow this. You would basically create two different views (profiles) for same type, and choose which one to use for serialization.

StaxMan