Jackson deserializes the null string as the body of the null query, which is expected (although it would be nice to disable this behavior).
The code below starts the check in case of payload "{}", but not in case of "zero" payload. This forces me to do another check for a zero payload, which does not seem normal to me, since PayloadValidator may include a zero check.
@InitBinder protected void initBinder(WebDataBinder binder) { binder.setValidator(new PayloadValidator()); } @RequestMapping(method = POST, value = "/my/path/here") public ResponseEntity<String> create( @Validated @RequestBody Payload payload ) { if (payload == null) {
- Is there a general way to reject null @RequestBody in general (i.e. for all endpoints)?
- If not, can I have all the validation logic in one place and start automatically (i.e. via @Validated or @Valid)?
Thanks, Emanuel
source share