I'm coding a Spring Web Service, using Jackson by default. I'm using @JsonView to indicate which property I need to be parsed to my JSON object. So, the problem is: Many objects are used in different classes, but not exactly all its properties, for example:
class Professor {
@JsonView({Views.Public.class, Views.Internal.class})
private int id;
@JsonView(Views.Internal.class)
private String name;
...
}
class Classroom {
@JsonView({Views.Public.class, Views.Internal.class})
private int id;
@JsonView(Views.Internal.class)
private String name;
...
}
class Lecture {
@JsonView(Views.Public.class)
private Professor professor;
@JsonView(Views.Public.class)
private Classroom classroom;
...
}
What if I need more than two 'perspectives', I'd have to create more interfaces/classes to do that? (like Views.Professor, Views.Principal, ...) Is this a real good practice?
I'd like to hear some suggestions or alternatives to solve that. I'm a little bit confused about being on the right track.