79791091

Date: 2025-10-15 11:12:22
Score: 2
Natty:
Report link

There is a change in the exception behavior that you receive from Spring version 3.4.7. If a @RequestBody is annotated as @Valid and the request object passed to it is null, the object will be created but all the fields within it will be null. If the POJO class to which this request object is mapped has @NotNull annotation in the fields, then that will result in 500 Internal server error due to ConstraintViolationException.

We can configure a GlobalExceptionHandler to throw Http Status Code 400 for any kind of Bad Request. GlobalExceptionHandler is generally annotated with @ControllerAdvice and will have a method annotated with @ExceptionHandler with the Exception class tagged with it.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • User mentioned (1): @RequestBody
  • User mentioned (0): @Valid
  • User mentioned (0): @NotNull
  • User mentioned (0): @ControllerAdvice
  • User mentioned (0): @ExceptionHandler
  • Low reputation (1):
Posted by: Sathya Priya