message: Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/json
Description: The server encountered an internal error (Could not find MessageBodyWriter for response object of type: java.util.ArrayList of media type: application/json) that prevented it from fulfilling this request
@GET
@Path("/{userName}/questions")
//@Produces("application/json")
public Response getUserQuestions(@PathParam("userName") String userName){
UserDAO userDAO = new UserDAO();
List<Question> questions = userDAO.getUserQuestionsByUserName(userName);
GenericEntity<List<Question>> entity = new GenericEntity<List<Question>>(questions){};
return Response.status(200).entity(entity).type(MediaType.APPLICATION_JSON).build();
}
我在类路径中有 resteasy jackson 提供程序。
尝试将返回类型从 ArrayList
更改为 List
,然后根据 resteasy response 将其包装在 GenericEntity
中, 但仍然遇到同样的问题。
在 tomcat7 上运行。
谢谢。
最佳答案
我通过将 resteasy-jackson-provider.jar 添加到类路径来解决这个异常 引用https://bitbucket.org/arcbees/gaestudio/issue/2/need-resteasy-jackson-provider-on
关于java - RestEasy:找不到 MessageBodyWriter 类型的响应对象:媒体类型的 java.util.ArrayList:application/json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19089781/