[英]Incorrect JSON entity produced from JAX-RS response builder
在我的 JAX-RS 资源中,我有如下authenticate
方法,它返回Response
对象。
public Response authenticate(@QueryParam("username") String username,
@QueryParam("password") String password) throws JSONException, org.json.JSONException {
JsonObjectBuilder jsonObjBuilder = Json.createObjectBuilder();
jsonObjBuilder.add( "auth_token", authToken );
JsonObject jsonObj = jsonObjBuilder.build();
System.out.println("jsonObject" + jsonObj);
return Response.status(200).entity(jsonObj).build();
}
jsonObject 在我的打印语句中是完美的,但我的实际响应是用
Response.status(200).entity(jsonObj).build();
看起来像这样:
{"auth_token":{"valueType":"STRING"}}
我希望响应如下所示:
("auth_token":"b88c1d32-2056-4c57-926d-e8213e875b7d")
用简单的 HashMap 替换过于复杂的 JsonObjectBuilder:
Map<String, String> jsonValues = new HashMap<>();
jsonValues.put("auth_token", authToken);
return Response.status(200).entity(jsonValues).build();
它应该生成:
{"auth_token":"b88c1d32-2056-4c57-926d-e8213e875b7d"}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.