![](/img/trans.png)
[英]How to convert Json to Java for making POST request using rest assured
[英]how to retrieve JSON request into method using rest java?
我正在为 rest 使用简单的 java 和 jersey。 下面是方法。 从 postman 我正在发送 json 请求,并希望在不声明 POJO class 的情况下将该数据检索到方法中。 但无法检索。
@Path("{entity}/markLabel")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response markLabel()
throws Exception {
}
我想将请求 json 参数(fileType,groupId,sourceId)检索到此请求 json 参数的方法中。
有人可以帮我吗?
为什么要以另一种方法检索请求参数或标头?
一种方法处理一个请求,就是这样,但是如果您想将某些功能隔离到单独的方法中,您可以在请求处理方法中调用另一种方法。
@Path("{entity}/markLabel")
@PUT
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response markLabel(ReqObject String reqBody) throws Exception {
//////do something
someOtherMethod(reqBody);
//////do something
}
class ReqObject{
String fileType;
String groupId;
String sourceId;
//getters and setters
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.