I have an application that sends api calls to another application, with this code:
objreq.setReq(request);
HttpEntity<Request> entity = new HttpEntity<Request>(objreq, headers);
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
where headers contains application/json of course.
The problem is, is that the objreq is set correctly, however, when it calls the other api:
@PostMapping
public ResponseEntity<Response> insertRequest(
@RequestBody @Valid Request request) {
requestService.insertRequest(request);
return ResponseEntity.ok(new ResponseSuccess<>());
}
all the fields are null. This is really annoying as the fields are set correctly in the request, but in everything is null in the response.
Note: this code works fine
restTemplate.postForObject(url, request, String.class);
Would like to know why the exchange does not work, unfortunately I don't have much experience with RestTemplate, so not sure if the issue is here. Many Thanks
根据本文档 , ok(T body)
从参数T body
构造ResponseSuccess
T body
,您传递了ResponseSuccess
对象,这可能是这里的问题,我不知道ResponseSuccess
类的内部内容(无法查找此类的文档,因此我无法确定问题可能在此类中的什么地方),但我会在那里查找问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.