I have restful web service which return list of users, i want to make response as json format but that produce the following exception:
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) )
my restful method:
@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();
}