class MethodArgumentNotValidExceptionHandler implements RestExceptionHandler<MethodArgumentNotValidException> {

    @Override
    public Object errorMessage(MethodArgumentNotValidException exception, HttpServletRequest request) {
        BindingResult bindingResult = exception.getBindingResult();
        int errorCount = bindingResult.getErrorCount();

        return String.join("", bindingResult.getObjectName(), " has ", String.valueOf(errorCount), " validation error",
                errorCount > 1 ? "s" : "");
    }

}