在将自定义对象传递到RequestEntity主体时,我将主体设为null,同时在RestController API中检索它。
我在其中设置RequestEntity的源代码
final BodyBuilder requestBuilder = RequestEntity.method(method, builder.build().toUri());
//Set Accept
if(accept != null) {
requestBuilder.accept(accept);
}
//Set Content-Type
if(contentType != null) {
requestBuilder.contentType(contentType);
}
//Add Headers
addHeadersToRequest(headerParams, requestBuilder);
addHeadersToRequest(defaultHeaders, requestBuilder);
//Set Body
RequestEntity<BusinessRequest> requestEntity = requestBuilder.body(requestBody);
ResponseEntity<BusinessResponse> responseEntity = restTemplate.exchange(requestEntity, BusinessResponse.class);
我要检索RestEntity的目标代码->
@GetMapping("/mcloed")
public ResponseEntity<BusinessResponse> getMcloedResponse(RequestEntity<BusinessRequest> request) throws Exception {
LOGGER.info("AdapterController : getMcloedResponse started");
BusinessResponse response = null;
adapterService.setAdapterHandler(mcloedAPIHandler);
response = adapterService.getMcloedResponse(request);
HttpHeaders headers = new HttpHeaders();
return ResponseEntity.accepted().headers(headers).body(response);
}
在这里,在目标代码request.getBody始终返回null。