private List<ValidationError> getFieldErrorsAsValidationErrors(Lang lang, BindingResult result) { return result.getFieldErrors().stream().map(error -> { String key = error.getObjectName() + "." + error.getField(); if (key.startsWith("target.") && rootName == null) { key = key.substring(7); } if (error.isBindingFailure()) { ImmutableList.Builder<String> builder = ImmutableList.builder(); final Messages msgs = lang != null ? new MessagesImpl(lang, this.messagesApi) : null; for (String code: error.getCodes()) { code = REPLACE_TYPEMISMATCH.matcher(code).replaceAll(Matcher.quoteReplacement(INVALID_MSG_KEY)); if (msgs == null || msgs.isDefinedAt(code)) { builder.add(code); } } final ImmutableList<String> messages = builder.build(); return new ValidationError(key, messages.isEmpty() ? Arrays.asList(INVALID_MSG_KEY) : messages.reverse(), convertErrorArguments(error.getArguments())); } else { return new ValidationError(key, error.getDefaultMessage(), convertErrorArguments(error.getArguments())); } }).collect(Collectors.toList()); }
private List<ValidationError> getFieldErrorsAsValidationErrors(Lang lang, BindingResult result) { return result.getFieldErrors().stream().map(error -> { String key = error.getObjectName() + "." + error.getField(); if (key.startsWith("target.") && rootName == null) { key = key.substring(7); } if (error.isBindingFailure()) { ImmutableList.Builder<String> builder = ImmutableList.builder(); final Messages msgs = lang != null ? new MessagesImpl(lang, this.messagesApi) : null; for (String code: error.getCodes()) { code = REPLACE_TYPEMISMATCH.matcher(code).replaceAll(Matcher.quoteReplacement(INVALID_MSG_KEY)); if (msgs == null || msgs.isDefinedAt(code)) { builder.add(code); } } final ImmutableList<String> messages = builder.build(); return new ValidationError(key, messages.isEmpty() ? Arrays.asList(INVALID_MSG_KEY) : messages.reverse(), convertErrorArguments(error.getArguments())); } else { return new ValidationError(key, error.getDefaultMessage(), convertErrorArguments(error.getArguments())); } }).collect(Collectors.toList()); }
private List<ValidationError> getFieldErrorsAsValidationErrors(Lang lang, BindingResult result) { return result.getFieldErrors().stream().map(error -> { String key = error.getObjectName() + "." + error.getField(); if (key.startsWith("target.") && rootName == null) { key = key.substring(7); } if (error.isBindingFailure()) { ImmutableList.Builder<String> builder = ImmutableList.builder(); final Messages msgs = lang != null ? new MessagesImpl(lang, this.messagesApi) : null; for (String code: error.getCodes()) { code = REPLACE_TYPEMISMATCH.matcher(code).replaceAll(Matcher.quoteReplacement(INVALID_MSG_KEY)); if (msgs == null || msgs.isDefinedAt(code)) { builder.add(code); } } final ImmutableList<String> messages = builder.build(); return new ValidationError(key, messages.isEmpty() ? Arrays.asList(INVALID_MSG_KEY) : messages.reverse(), convertErrorArguments(error.getArguments())); } else { return new ValidationError(key, error.getDefaultMessage(), convertErrorArguments(error.getArguments())); } }).collect(Collectors.toList()); }