I have a Spring 4.3.3 @RestController
which manages an entity type via List
s.
@RestController
@RequestMapping("...")
public class EntityRestController {
@PostMapping
public void doSomeWork(@RequestBody final List<Entity> entities) { ... }
}
I discovered sometimes I may receive a request where the body consists not of an array, but a single JSON object. I'm using Gson as the default serializer/deserializer and obviously it throws an exception.
JSON parse error: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT
What would the better way to tackle this problem be (at the Controller level)?