Failed to instantiate [java.util.List]: Specified class is an interface in HTTP controller handler?


Problem Use case:

Following SpringBoot Rest Controller is not able to map the request payload

@Controller
@RequestMapping("/api")
  public class BlogController {  
    @RequestMapping(value = "/blogstories", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
       public ResponseEntity<List<BlogStoryObject>> addUpdateblog(List<BlogStoryObject> blogItems) {
          List<BlogStoryObject> result = new ArrayList<BlogStoryObject>();
    //TODO:: Call Service to update/save objects
    return new ResponseEntity<List<RootBlogStoryObject>>(result, HttpStatus.OK);
 }
}


Exception Details [Truncated]:

And the error thrown at runtime is Failed to instantiate [java.util.List]: Specified class is an interface.

Solution

Solution to the problem is to @RequestBody annotation to the method definition, so the following will work.

public ResponseEntity<List<RootBlogStoryObject>> addUpdateblog(
  @RequestBody List<RootBlogStoryObject> blogItems) {
  /////implementation goes here

}

Comments

Popular posts from this blog

Converting Java Map to String

Difference between volatile and synchronized

Invoking EJB deployed on a remote machine