我创建了一个网络服务功能:
@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;
}
该函数返回一个结果列表:如果我在选择 application/json 选项时使用浏览器对其进行测试,它可以正常工作:
结果:
[[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]]
但是当我选择“应用程序/xml”时,它给了我一个错误:
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
谁能帮助我并告诉我它有什么问题?
另外我怎样才能返回一个格式良好的结果,如下所示?
<id>1</id>
<name>Ankit</name>
我知道我需要为它使用一个类,但由于这是一个本机查询,我使用两个表并返回一个结果列表,我不知道该怎么做。