How to filter response of a JAX-RS service?

I got the following value object:

public class Movie{
  public String name;
  public Date releaseDate;
  public List<Actors> actors;

and i got the following service

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.

preguntado el 31 de julio de 12 a las 10:07

2 Respuestas

If you never want to include the actors field in your response, you can annotate the field with @XmlTransient. Consulte las Javoc para más información.

Otherwise, you could wrap the Movie object into a wrapper object that doesn't expose the actors campo.

Respondido 31 Jul 12, 10:07

If the service has no method that does it, you'll have to change the service code itself.

Respondido 31 Jul 12, 10:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.