I got the following value object:
@XmlRootElement
public class Movie{
public String name;
public Date releaseDate;
public List<Actors> actors;
}
and i got the following service
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Movie> moviesByYear(int year){
//return all movies by year
}
The movies are searched in the database by some ORM framework. My question is: I want to filter the response, to not return the actors list (because this field is not relevant, and makes the response larger). Of course I can
for(Movie movie: movies){
movie.actors = null;
}
but this will escalate quickly if I want to remove multiple fields.
If you never want to include the
actorsfield in your response, you can annotate the field with@XmlTransient. See the JavaDoc for more details.Otherwise, you could wrap the
Movieobject into a wrapper object that doesn’t expose theactorsfield.