使用RestTemplate获取JSON对象时,获取HttpMessageNotReadableException异常

时间:2019-02-27 13:33:11

标签: java spring api resttemplate

所以我正在使用REST客户端的REST客户端上使用Spring RestTemplate来获取json对象。我正在使用api键设置必要的标头。触发请求时,我一直收到此错误。

Could not read document: Can not construct instance of io.sample.poynt.client.domain.PoyntBusinessDetails$Address: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: java.io.PushbackInputStream@4ee48093; line: 1, column: 13] (through reference chain: io.sample.poynt.client.domain.PoyntBusinessDetails["address"])

代码段:

 RestTemplate restTemplate = new RestTemplate();
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.set(API_VERSION_HEADER, "1.2");
    headers.set(AUTHORIZATION_HEADER, apiToken);
    HttpEntity entity = new HttpEntity(headers);
    ResponseEntity<PoyntBusinessDetails> response = restTemplate.exchange(
            poyntCloudBusinessUrl+businessId, HttpMethod.GET, entity, PoyntBusinessDetails.class);

PoyntBusinessDetails类:

public class PoyntBusinessDetails {

private String mockProcessor;
private String createdDate;
private String updatedDate;
private String activatedDate;
private String status;
private String type;
private Attribute attribute;
private Address address;
private Phone phone;
private String acquirer;
private String processor;
private String externalMerchantId;
private String legalName;
private String businessUrl;
private String emailAddress;
private String doingBusinessAs;
private String industryType;
private String mcc;
private String sic;
private String timezone;
private String id;

 public PoyntBusinessDetails() {
}

// getters and setters
}

private class Address {

    // fields

    // getters and setters
}

private class Attribute {

    // fields

    // getters and setters
}


private class Phone {

    // fields
    // getters and setters
 }

}

所以在这里,我将从API端点附加示例请求。 (我从邮递员那里得到)

{
"address": {
   //fields
},
"mockProcessor": false,
"status": "ACTIVATED",
"type": "MERCHANT",
"activeSince": "1970-01-01T00:00:00Z",
"createdAt": "2019-02-04T21:30:16Z",
"updatedAt": "2019-02-19T15:45:52Z",
"attributes": {
    //fields
},
"phone": {
    //fields
},
"acquirer": "xxxx",
"processor": "xxxx",
"externalMerchantId": "xxxx",
"legalName": "OLYMPUS",
"businessUrl": " www.xxxx.com",
"emailAddress": "accounting@xxxx.com",
"doingBusinessAs": "OLYMPUS",
"industryType": "Retail",
"mcc": "5999",
"sic": "5999",
"timezone": "America/Los_Angeles",
"id": "xxxx"
}

我在这里想念什么或做错什么了?

0 个答案:

没有答案