如何返回 XML 或 JSON 格式的问题对象列表?
@Path("all")
@GET
public List<Question> getAllQuestions() {
return questionDAO.getAllQuestions();
}
我得到这个异常:
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
最佳答案
尝试:
@Path("all")
@GET
public ArrayList<Question> getAllQuestions() {
return (ArrayList<Question>)questionDAO.getAllQuestions();
}
如果您的目标是返回您可以使用的项目列表:
@Path("all")
@GET
public Question[] getAllQuestions() {
return questionDAO.getAllQuestions().toArray(new Question[]{});
}
编辑 在上面添加了原始答案
关于java - 使用 JAX-RS 时返回对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8165908/