DTO:
public class User {
@NotNull
private String name;
@NotNull
private String password;
//..
}
Controller:
I know this is kind of old question,
But I just run into it and I found some pretty good article which has also a perfect example in github.
Basically it uses @ControllerAdvice
as Spring documentation suggests.
So for example catching 400 error will be achieved by overriding one function:
@ControllerAdvice
public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
@Override
protected ResponseEntity
(ApiError class is a simple object to hold status, message, errors)