There is a controller

@RestController public class HandlerRequest { @GetMapping("/schedule") @RequestMapping(method = RequestMethod.POST) @ResponseBody public List<Meeting> build(@RequestBody List<BookingRequest> bookingRequests, @RequestBody String workTime) { return Builder.build(bookingRequests, workTime); } 

I send json through Postman

 { "bookingRequests" : [] , "workTime" : "1130 1730" } 

The answer comes

 { "timestamp": 1507146731039, "status": 400, "error": "Bad Request", "message": "JSON parse error: Cannot deserialize instance of java.util.ArrayList out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.util.ArrayList out of START_OBJECT token\n at [Source: (PushbackInputStream); line: 1, column: 1]", "path": "/schedule" } 

    1 answer 1

    The body of the Post request can only be one. You need to make a wrapper class for all parameters and pull parameters out of the method body. Type something like this :

     @GetMapping("/schedule") @RequestMapping(method = RequestMethod.POST) @ResponseBody public List<Meeting> build(@RequestBody Data data) { return Builder.build(data.bookingRequests, data.workTime); } public static class Data { public List<BookingRequest> bookingRequests; public String workTime; } 

    And in the error you said that when you tried to parse the body as a list of objects, in fact, the object turned out to be, which led to a fall.

    • You can also, without creating a wrapper class, define the type of the request body as Map<String, String> - stackoverflow.com/a/33749674/3212712 - YuriSPb
    • Got it, thanks a lot - flagmen
    • In general, I thought that Spring is a very powerful thing, it’s strange that you can’t do that - flagmen
    • @flagmen, I am not an expert and have never had a case with spring, but, as I understand it, this is a limitation of the standard Http requests - there can be many parameters, but there can only be one body. On the other hand, it seems, you can somehow transfer the body from several parts - through another annotation - stackoverflow.com/a/31753785/3212712 - JuriySPb