Я получаю следующую ошибку при попытке получить доступ к API REST
и получить ответ JSON, используя RestTemplate
.
Ошибка:
Can not construct instance of io.sample.clover.client.domain.BusinessOrder$Customer: no suitable constructor found, can not deserialize from Object value.
(through reference chain: io.sample.clover.client.domain.BusinessOrder["customers"]->io.sample.clover.client.domain.BusinessOrder$Customers["elements"]->java.util.ArrayList[0])
Фрагмент кода:
public BusinessOrder getOrderById(String businessId,String orderId) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.add("Content-Type", "application/json");
requestHeaders.add("Authorization", "xxxxxxx");
HttpEntity entity = new HttpEntity(requestHeaders);
ResponseEntity<BusinessOrder> response = restTemplate.exchange(cloverApiBaseUrl + "merchants/"+businessId+"/orders/"+orderId+"?expand=lineItems&expand=payments&expand=customers", HttpMethod.GET, entity, BusinessOrder.class);
return response.getBody();
}
Класс модели BusinessOrder:
public class BusinessOrder {
private String id;
private String currency;
private Customers customers;
private Employee employee;
private int total;
private String title;
private String note;
private boolean taxRemoved;
private boolean isVat;
private String state;
private boolean manualTransaction;
private boolean groupLineItems;
private boolean testMode;
private String payType;
private String createdTime;
private String modifiedTime;
private LineItems lineItems;
private Payments payments;
@JsonIgnoreProperties(ignoreUnknown = true)
public BusinessOrder() {
}
public class Customers {
private List<Customer> elements;
@JsonGetter("elements")
public List<Customer> getElements() {
return elements;
}
}
public class LineItems {
private List<LineItem> elements;
@JsonGetter("elements")
public List<LineItem> getElements() {
return elements;
}
}
public class Payments {
private List<Payment> elements;
@JsonGetter("elements")
public List<Payment> getElements() {
return elements;
}
}
public class Employee {
private String id;
}
public class LineItem {
private String id;
private OrderRef orderRef;
private Item item;
private String name;
private double price;
private boolean printed;
private int createdTime;
private boolean exchanged;
private boolean refunded;
private boolean isRevenue;
}
public class OrderRef {
private String id;
}
public class Item {
private String id;
}
public class Payment {
private String id;
private Order order;
private Device device;
private Tender tender;
private int amount;
private int tipAmount;
private int taxAmount;
private int cashbackAmount;
private Employee employee;
private int createdTime;
private int modifiedTime;
private boolean offline;
private String result;
public class Order {
private String id;
}
public class Device {
private String id;
}
public class Tender {
private String id;
}
public class Customer {
private String id;
private OrderRef orderRef;
private String firstName;
private String lastName;
private Boolean marketingAllowed;
private Long customerSince;
public class OrderRef {
private String id;
}
}
}
}
Внутри этого класса модели BusinessOrder существуют другие классы модели.включены как внутренние классы.Каждый идентификатор класса имеет конструктор по умолчанию и соответствующие методы getter и setter.
Ответ json, который нужно отобразить с помощью схемы pojo, может быть показан следующим образом:
{
"id": "xxxxx",
"currency": "USD",
"customers": {
"elements": [
{
"id": "xxxxx",
"orderRef": {
"id": "xxxxx"
},
"firstName": "sajitj",
"lastName": "",
"marketingAllowed": false,
"customerSince": 1546840522000
}
]
},
"employee": {
"id": "xxxxx"
},
"total": 23,
"title": "5",
"note": "xxxx",
"taxRemoved": false,
"isVat": false,
"state": "locked",
"manualTransaction": false,
"groupLineItems": true,
"testMode": false,
"payType": "FULL",
"createdTime": 1551788021000,
"clientCreatedTime": 1551788021000,
"modifiedTime": 1551788050000,
"lineItems": {
"elements": [
{
"id": "xxxxx",
"orderRef": {
"id": "xxxx"
},
"item": {
"id": "xxxxx"
},
"name": "Blueberryy Cheesecake",
"price": 20,
"printed": true,
"createdTime": 1551788020000,
"orderClientCreatedTime": 1551788021000,
"exchanged": false,
"refunded": false,
"isRevenue": true
}
]
},
"payments": {
"elements": [
{
"id": "xxxxx",
"order": {
"id": "xxxx"
},
"device": {
"id": "xxxxx"
},
"tender": {
"id": "xxxx"
},
"amount": 23,
"tipAmount": 0,
"taxAmount": 1,
"cashbackAmount": 0,
"employee": {
"id": "xxxx"
},
"createdTime": 1551788028000,
"clientCreatedTime": 1551788027000,
"modifiedTime": 1551788035000,
"offline": false,
"result": "SUCCESS"
}
]
}
}
Любая идея для решения приветствуется.