因此,我正在使用REST客户端,该客户端使用REST API来使用Spring RestTemplate获取JSON对象。所以我得到一个HTTP 200 OK响应,但是类对象内的列表(设备)为空。但是其他领域也被获取。当我使用邮递员执行相同的请求时,效果很好。可能是什么原因?
RestTemplate代码段:
RestTemplate restTemplate = new RestTemplate();
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Content-Type", "application/json");
requestHeaders.add("Authorization", "Bearer " + apiToken);
HttpEntity entity = new HttpEntity(requestHeaders);
ResponseEntity<CloverMerchant> response = restTemplate.exchange(getMerchantDetailsUrl, HttpMethod.GET, entity, CloverMerchant.class);
return response.getBody();
CloverMerchant模型类:
private String id;
private String name;
private String website;
private boolean isBillable;
private CloverBusinessEquipments equipment;
// other relevant getters and setters
CloverBusinessEquipments模型类:
private List<CloverBusinessEquipment> elements;
// relevant getters and setters
CloverBusinessEquipment模型类:
private String merchantId;
private String serialNumber;
private String equipmentCode;
private String equipmentCodeDesc;
private String provisionedDeviceType;
private boolean boarded;
private boolean provisioned;
// relevant getters and setters
REST API的响应JSON:
{
"id": "5ZTFCGXQKVZNA",
"name": "xxxx",
"website": "https://xxxx.io",
"isBillable": false,
"equipment": {
"elements": [
{
"merchantId": "5ZTFCGXQKVZNA",
"boarded": false,
"provisioned": true,
"serialNumber": "C030UQ71040182",
"equipmentCode": "105J",
"equipmentCodeDesc": "Clover Mini",
"provisionedDeviceType": "MAPLECUTTER"
},
{
"merchantId": "5ZTFCGXQKVZNA",
"boarded": false,
"provisioned": true,
"serialNumber": "C050UQ75150054",
"equipmentCode": "1297",
"equipmentCodeDesc": "Clover Station 2018",
"provisionedDeviceType": "GOLDENOAK"
}
]
}
}