Мне нужно десериализовать этот JSON:
{
"order":{
"address": "Adress XXX",
"status": "Open",
"confirmationDates": "2019-04-03"
},
"orderItems": [
{
"description": "Item 1",
"unitPrice": 10.5,
"quantity": 2
},
{
"description": "Item 2",
"unitPrice": 22.5,
"quantity": 2
},
{
"description": "Item 3",
"unitPrice": 10000.5,
"quantity": 2
}
]
}
Я использую Spring Boot и у меня есть запрос Post с этим телом.
@PostMapping("/orderwithitems")
public ResponseEntity<Object> addOrderWithItems(@RequestBody OrderOrderItem orderOrderItem){...}
Класс Wrapper - это POJO:
public class OrderOrderItem{
private Order order;
private List<OrderItem> orderItems;
public OrderOrderItem(){
orderItems = new ArrayList<>();
order = new Order();
}
public OrderOrderItem(Order order, List<OrderItem> orderItems) {
this.order = order;
this.orderItems = orderItems;
}
...
}
Проблема в том, что когда я делаю пост, я получаю эту ошибку:
{
"timestamp": "2019-04-04T23:04:19.640+0000",
"status": 400,
"error": "Bad Request",
"message": "JSON parse error: Cannot construct instance of `com.invillia.acme.OrderController$OrderOrderItem` (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.invillia.acme.OrderController$OrderOrderItem` (although at least one Creator exists): can only instantiate non-static inner class by using default, no-argument constructor\n at [Source: (PushbackInputStream); line: 2, column: 2]",
"path": "/orderwithitems"
}
Я пытаюсь следовать этим примерам: https://www.baeldung.com/jackson-collection-array
https://www.baeldung.com/spring-rest-template-list
Но я не могу найти решение.