Skip to content
Advertisement

SpringBoot DTO Validation

I am new to spring-boot I’m trying to add validation to my DTO class like below.

JavaScript

Below is my REST endpoint to save employee.

JavaScript

I create a Validation class like below to validate the DTO fields.

JavaScript

expected output is

{ “firstName”:”Employee first name is required”, “employeeNum”:”EmployeeNUM is required” }

But I’m getting only the 400 bad request when hit the endpoint through postman. What is the issue with my code? How to fix and get the expected output as mentioned above?

Advertisement

Answer

Try to extend the ResponseEntityExceptionHandler class like this:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement