@ControllerAdvice
public class CustomHandle {
@ResponseBody
@ExceptionHandler(MethodArgumentNotValidException.class)
public String methodArgumentNotValidExceptionHandle(MethodArgumentNotValidException e) {
List<ObjectError> allErrors = e.getAllErrors();
List<String> errorsMessages = allErrors.stream()
.map(error -> error.getDefaultMessage())
.collect(Collectors.toList());
return errorsMessages.toString();
}}