[英]trying to build a Response object for a Java RESTful service
I am trying to build a Response object with a information I am getting back from a database. 我正在尝试使用从数据库中获取的信息来构建Response对象。 The information I am getting back is in a Change object:
我返回的信息在Change对象中:
The change.getDocument()
coming back is: 返回的
change.getDocument()
是:
{"testSolution":false,"solutionId":333,"clientId":4018593,"firewall":false,"pod":"pod3.dmy3","networkPolicy":{"speed":"1","subnets":{"nat":{"vlan":3004,"cidr":["110.168.0.0/24"]},"private":{"vlan":3004,"cidr":["15.10.1.128/25"]}}}}
So I am creating a Response like this: 所以我正在创建这样的响应:
return Response.status(422).location(location).entity(changeRequest).build();
In the unit test I do this: 在单元测试中,我这样做:
String responseJson = response.readEntity(String.class);
System.out.println("The response is: " + responseJson);
For testing, but I get this result: 为了测试,但我得到了以下结果:
The response is: {"object_id" : 333,"object_type" : "class com.entities.Solution", "operation" : "", "revision" : 0, "remote_user" : "", "remote_host" : "", "created" : "", "published" : "", "comment" : "HTTP Status Code 422", "error" : "HTTP Status Code 422, there is a pending change request for this Solution. Replying with pending ChangeRequest", "document" : {} }
Everything is as expected, but the document node contains no information. 一切都按预期进行,但是文档节点不包含任何信息。 Am I building the Response object correctly?
我是否正确构建Response对象?
Try to return it in this way: 尝试以这种方式返回它:
Response.status(Status.OK).type(MediaType.APPLICATION_JSON)
.entity(changeRequest).build();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.