79791132

Date: 2025-10-15 11:56:34
Score: 2.5
Natty:
Report link

To get the expected exception in the desired format, GlobalExceptionHandler can be used usually annotated with @ControllerAdvice. But for the custom exception format and the expected HttpCode to work as expected, few other configurations have to be taken into consideration. In API end point along with @RequestBody , you have to add @Valid annotation to consider the request body for validation. The POJO class against which this request object will be mapped should have the @NotNull and similar annotations on fields as required. Also, ensure pom file includes the necessary dependency to support the annotation driven validations.

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