looking for some solutions? You are welcome.

SOLVED: Having null response for a list of objects in REST API call with RestTemplate

JohnDoe921:

So I'm working on a REST client that consumes a REST API to get a JSON object using the Spring RestTemplate. So I get an HTTP 200 OK response but the list (equipment) inside the class object is null. But other fields are fetched. When I do the same request using the Postman it works well. What might be the reason for this?

The RestTemplate code snippet :

 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();

The CloverMerchant model class :

private String id;
private String name;
private String website;
private boolean isBillable;
private CloverBusinessEquipments equipment;

// other relevant getters and setters

The CloverBusinessEquipments model class:

private List<CloverBusinessEquipment> elements;

    public CloverBusinessEquipments() {
}

@JsonGetter("elements")
public List<CloverBusinessEquipment> getElements() {
    return elements;
}

The CloverBusinessEquipment model class :

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

The expected response JSON from the REST API:

{
  "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"
       }
    ]
  }
}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent