Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring boot - how to avoid "Failed to instantiate [java.util.List]: Specified class is an interface" in HTTP controller handler?

In my spring boot REST API application, I need to handle HTTP POST by accepting a strongly-typed list as my input:

@RestController
public class CusttableController {

    static final Logger LOG = LoggerFactory.getLogger(CusttableController.class);

    @RequestMapping(value="/custtable/update", method=RequestMethod.POST)
    @ResponseBody
    public String updateCusttableRecords(List<Custtable> customers) {
        try {
                for (Custtable cust : customers) {

                Custtable customer = (Custtable) custtableDao.getById(Custtable.class, 
                        new CusttableCompositeKey 
                        (cust.getAccountnum(),cust.getPartition(),cust.getDataareaid()));

In the Jersey version of this API, this worked just fine, but with Spring Boot, it gives me this error:

org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface

What is the proper way for me to accept a strongly-typed List in Spring Boot?

like image 617
Eugene Goldberg Avatar asked Sep 10 '16 15:09

Eugene Goldberg


1 Answers

Try to add RequestBody annotation to your method definition

@RequestMapping(value="/custtable/update", method=RequestMethod.POST)
@ResponseBody
public String updateCusttableRecords(@RequestBody List<Custtable> customers) {
    //Method body 
}
like image 159
Egor Lyashenko Avatar answered Nov 03 '22 07:11

Egor Lyashenko