【发布时间】:2016-12-17 21:31:02
【问题描述】:
我有一个返回用户列表的宁静网络服务,我想以 json 格式做出响应,但会产生以下异常:
SEVERE: Servlet.service() for servlet [RESTful] in context with path [/spring] threw exception
org.codehaus.jackson.map.JsonMappingException: No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) )
我的宁静方法:
@GET
@Path("all")
@Produces(MediaType.APPLICATION_JSON)
public Response getUsers(){
UserService service = new UserService();
List<UserBean> userBeans = service.getUsers();
JSONObject users = new JSONObject();
if(userBeans != null)
{
for(UserBean user : userBeans)
{
users.put("name",user.getUsername());
}
System.out.println(users);
return Response.status(200).entity(users).build();
}
return Response.status(201).entity("faild").build();
}
【问题讨论】:
-
你在用 Jersey 吗?
-
是的,我用过,有什么问题吗??