【发布时间】:2016-05-23 06:45:40
【问题描述】:
我有一个返回 Map<String, ArrayList<EntityClass>> 的方法。代码如下Definition类:
public Map<String, ArrayList<EntityClass>> webMethod1(){
ArrayList<EntityClass> arr = new ArrayList<>();
for (int i=0;i<5;i++){
arr.add(new EntityClass(i, String.valueOf(i)));
}
Map<String, ArrayList<EntityClass>> map = new HashMap<>();
map.put("Entity", arr);
}
进一步这由 Web 服务调用,如下所示:
@GET
@Path("/m1")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, ArrayList<EntityClass>> m1(){
return new Definition().webMethod1();
}
但我在控制台上得到了关注:
MessageBodyWriter not found for media type=application/json, type=class java.util.HashMap, genericType=class java.util.HashMap.
和HTTP 500 错误。
如何解决这个错误
【问题讨论】:
-
您需要将
Map转换为 json,使用 Jersey 为您提供的任何包装器/类。 -
我是新手,你能详细解释一下吗
-
您使用的是哪个 Jersey 版本? 1.x 还是 2.x?
-
另见another question。一点点搜索不会是坏事......