How can I return a list of Question objects in XML or JSON?
@Path("all")
@GET
public List<Question> getAllQuestions() {
return questionDAO.getAllQuestions();
}
I get this exception:
SEVERE: Mapped exception to response: 500 (Internal Server Error) javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class java.util.Vector, and Java type java.util.List, and MIME media type application/octet-stream was not found
Try:
@Path("all")
@GET
public ArrayList<Question> getAllQuestions() {
return (ArrayList<Question>)questionDAO.getAllQuestions();
}
If your goal is to return a list of item you can use:
@Path("all")
@GET
public Question[] getAllQuestions() {
return questionDAO.getAllQuestions().toArray(new Question[]{});
}
Edit Added original answer above