Usually it would work by adding `@JsonIgnoreProperties` on `children`, but in this case type is `Set`, which is not a POJO. Likewise I don't think you can currently specify separate view for property, as `@JsonView` on property simply defines inclusion of that property.
One way this could work would be to specify interface that only includes `X` and `Z`, implemented by `entityB` and then specify something like: @JsonSerialize(contentAs=XZInterface.class) public Set<entityB> to enforce serialization of a subset of properties. -+ Tatu +- On Tue, Aug 9, 2016 at 1:32 PM, Rj Ewing <[email protected]> wrote: > I need some help serializing 2 entities: > > entityA { > public String A; > public Set<entityB> children; > } > > entityB { > public String X; > public String Y; > public String Z; > } > > When entityA is serialized, I would like "String X" and "String Z" to be > serialized for entityB. However, when entityB is serialized on it's own > (not as part of entityA children), I would like all properties to be > serialized. > > How can I go about doing this. It doesn't appear that I can have > @JsonIdentityInfo objects, only single property. Is there a way I can have > a "default" JsonView for a class and then specify a "custom" JsonView when > I only want to serialize String X & Y of entityB? I would rather not have > to specify @JsonView on every REST service that serializes entityB. > > > > > -- > You received this message because you are subscribed to the Google Groups > "jackson-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
