Eugene Goldberg Eugene Goldberg - 2 months ago 26
Java Question

spring boot - how to avoid "Failed to instantiate [java.util.List]: Specified class is an interface" in HHTP 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?

Answer

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 
}
Comments