我正在用maven学习JERSEY REST API。我遇到以下错误乳清我打GET请求。有趣的一点是当我只返回特定的类对象时,我得到了期望的结果,但是当我返回所有这些对象的地图时,出现状态500 - 内部服务器错误。请建议。Json响应泽西REST应用程序中的严重错误
错误:
SEVERE: MessageBodyWriter not found for media type=application/json,
type=class java.util.HashMap, genericType=java.util.Map<java.lang.Integer, message.Message>.
容易出错:
@GET
@Produces(MediaType.APPLICATION_JSON)
public Map<Integer,Message> getAll(){
ms.sample();
return ms.getAllMessages();
}
相同的代码,但返回的特定对象,做工精细:
@GET
@Produces(MediaType.APPLICATION_JSON)
public Message getAll(){
ms.sample();
return ms.getAllMessages().get(1);
}
PS:我已在JSON相关元素pom.xml文件如下
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
我使用Maven v2.16
你有杰克逊依赖? – sidgate