I have created a web service function:
@GET
@Path("getusers/")
@Produces({"application/xml","application/json"})
public Object getUsers()
{
String distanceQuery="SELECT UGL.user_id,UP.fname,UGL.mlatitude,UGL.mlogitude,UGL.mlogitude from user_gps_location UGL,user_profile UP where UGL.user_id=UP.user_id";
Query queryResult=em.createNativeQuery(distanceQuery);
userList=queryResult.getResultList();
return userList;
}
The function returns a list of results: It works fine if I test it with my browser while I select the application/json option:
Result:
[[1,"Ankit",37.334542,-121.890821,-121.890821],
[1,"Ankit",37.337749,-121.886702,-121.886702],
[1,"Ankit",37.336453,-121.884985,-121.884985],
[1,"Ankit",37.336453,-121.884985,-121.884985],
[1,"Ankit",37.336453,-121.884985,-121.884985],
[1,"Ankit",32.727798,-117.15683,-117.15683],
[1,"Ankit",37.334541666666674,-121.89081999999999,-121.89081999999999],
[1,"Ankit",37.33774833333334,-121.88670166666667,-121.88670166666667],
[1,"Ankit",37.33774833333334,-121.88670166666667,-121.88670166666667],
[1,"Ankit",37.334541666666674,-121.89081999999999,-121.89081999999999],
[1,"Ankit",37.334541666666674,-121.89081999999999,-121.89081999999999],
[1,"Ankit",37.33774833333334,-121.88670166666667,-121.88670166666667],
[2,"Niharika",37.334541666666674,-121.88670166666667,-121.88670166666667],
[2,"Niharika",37.334541666666674,-121.88670166666667,-121.88670166666667]]
but when I select "application/xml" it gives me an error:
javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message body writer for Java class java.util.Vector, and Java type class java.util.Vector, and MIME media type application/xml was not found
Can anyone help me and tell me what's wrong with it?
Also How I can return a well formed result like below?
<id>1</id>
<name>Ankit</name>
I know I need to use a class for it but as this is a native query and I use two tables and also return a result list, I don't know how to do that.