消息:找不到类型的响应对象的MessageBodyWriter:java.util.Array媒体类型的列表:application / json描述:服务器遇到内部错误(无法找到类型的响应对象的MessageBodyWriter:java.util.ArrayList of媒体类型:application / json)阻止它完成此请求
@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();
}
我在classpath中有resteasy jackson提供程序 . 尝试将返回类型从 ArrayList
更改为 List
,然后根据resteasy response将其包装在 GenericEntity
中,但仍然遇到同样的问题 .
在tomcat7上运行 .
谢谢 .
4 回答
我通过在classpath中添加resteasy-jackson-provider.jar来解决这个异常 . 参考https://bitbucket.org/arcbees/gaestudio/issue/2/need-resteasy-jackson-provider-on
最后使用
Gson library
而不是依赖于json解决了它 . 也没有包装在通用实体中 . 这是有效的代码不得不使用排除策略来避免循环引用 . 这是链接:stackoverflow error during json conversion (hibernate bi-directional mapping)
通过在ArrayList中使用的类中添加@XMLRootElement来解决相同的问题
通过添加此依赖项,我能够解决此问题 .