I got this error. I tried add to properties this code: "spring.jackson.deserialization.accept-single-value-as-array=true" but i can't solve this problem?
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token at [Source: java.io.PushbackInputStream@2e64d73; line: 1, column: 145] (through reference chain: com.test.mobil.viewmodel.CompanyViewModel ["customerList"])
CustomerViewModel
public class CustomerViewModel {
private String name;
private String surname;
private int birthDate;
public CustomerViewModel(){}
public CustomerViewModel(String name, String surname, int birthDate) {
this.name = name;
this.surname = surname;
this.birthDate = birthDate;
}
}
CompanyViewModel
public class CompanyViewModel {
private String company;
private List<CustomerViewModel> customerList;
public CompanyViewModel(){}
public CompanyViewModel(String company, List<CustomerViewModel> customerList) {
this.company = company;
this.customerList = customerList;
}
}
CustomerController
@Controller
public class CustomerController {
@PostMapping("/customer")
public void setCustomer(@RequestBody CompanyViewModel companyViewModel){
System.out.println(companyViewModel);
}
}
JSON
page = {
company: "Facebook",
customerList = [
{
name: "Test1",
surname: "Test2",
birthDate: 1987
},
{
name: "Test3",
surname: "Test4",
birthDate: 1988
}
]
}