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.
If there are fields in Java objects that do not wish to be serialized, we can use the @JsonIgnore annotation in the Jackson library. The @JsonIgnore can be used at the field level, for ignoring fields during the serialization and deserialization.
To ignore individual properties, use the [JsonIgnore] attribute. You can specify conditional exclusion by setting the [JsonIgnore] attribute's Condition property. The JsonIgnoreCondition enum provides the following options: Always - The property is always ignored.
The Jackson @JsonIgnore annotation can be used to ignore a certain property or field of a Java object. The property can be ignored both when reading JSON into Java objects and when writing Java objects into JSON.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With