【发布时间】:2020-10-24 19:22:01
【问题描述】:
我想将输出 JSON 的属性设置为输入值,因此对于每个请求,属性名称都会发生变化。
这是我的网络服务的获取请求 URL:
http://10.0.75.1:7001/polling/Z2074350/ -> Z2074350 是我需要创建 JSON 属性的值:
我如何做到这一点?
我的控制器如下所示:
@GetMapping(value = "/batchpolling/{waybill}/{cp_id}", headers="Accept=application/json", produces="application/json")
public ResponseEntity<BatchPollingResponse> getBatchPollingResponse( @PathVariable("waybill") String waybill) throws JsonProcessingException {
BatchPollingResponse batchPollResponse = null;
try {
----------------------
batchPollResponse = restTemplate.getForObject(url, BatchPollingResponse.class);
----------------------
}catch(Exception e) {
LOGGER.error("Error processing OrderCreationMPS - getBatchPollingResponse");
e.printStackTrace();
}
return new ResponseEntity<BatchPollingResponse>( batchPollResponse, HttpStatus.OK );
}
我的 JSON 输出如下:
"result": {
"**Z2074350**": {
"latest_status": {
"status": "delivered"
}
}
}
【问题讨论】: