I have a class which holds a collection of another class.
class A{
@JsonView(VerboseViewA.Minimal.class)
String field1;
@JsonView(VerboseViewA.Complete.c
After struggling with the same problem, I came up to this solution:
class A
{
@JsonView(VerboseViewA.Minimal.class)
String field1;
@JsonView(VerboseViewA.Complete.class)
String field2;
@JsonView(VerboseViewA.Complete.class)
@JsonSerialize(using = VerboseMinimalSerializer.class)
Collection bEntities;
}
class B
{
@JsonView(VerboseViewB.Minimal.class)
String field2;
@JsonView(VerboseViewB.Complete.class)
String field3;
}
Now when serializing an instance of class A using VerboseViewA.Complete.class, bEnitities will be included and serialized using a custom VerboseMinimalSerializer, overriding its JsonView:
public class VerboseMinimalSerializer extends JsonSerializer
Notice this custom serializer is using the view VerboseViewB.Minimal.class.