use of org.springframework.validation.ObjectError in project spring-boot by spring-projects.
the class BindFailureAnalyzer method analyze.
@Override
protected FailureAnalysis analyze(Throwable rootFailure, BindException cause) {
if (CollectionUtils.isEmpty(cause.getAllErrors())) {
return null;
}
StringBuilder description = new StringBuilder(String.format("Binding to target %s failed:%n", cause.getTarget()));
for (ObjectError error : cause.getAllErrors()) {
if (error instanceof FieldError) {
FieldError fieldError = (FieldError) error;
description.append(String.format("%n Property: %s", cause.getObjectName() + "." + fieldError.getField()));
description.append(String.format("%n Value: %s", fieldError.getRejectedValue()));
}
description.append(String.format("%n Reason: %s%n", error.getDefaultMessage()));
}
return new FailureAnalysis(description.toString(), "Update your application's configuration", cause);
}
use of org.springframework.validation.ObjectError in project spring-framework by spring-projects.
the class BindStatus method initErrorCodes.
/**
* Extract the error codes from the ObjectError list.
*/
private void initErrorCodes() {
this.errorCodes = new String[this.objectErrors.size()];
for (int i = 0; i < this.objectErrors.size(); i++) {
ObjectError error = this.objectErrors.get(i);
this.errorCodes[i] = error.getCode();
}
}
use of org.springframework.validation.ObjectError in project spring-framework by spring-projects.
the class BindStatus method initErrorCodes.
/**
* Extract the error codes from the ObjectError list.
*/
private static String[] initErrorCodes(List<? extends ObjectError> objectErrors) {
String[] errorCodes = new String[objectErrors.size()];
for (int i = 0; i < objectErrors.size(); i++) {
ObjectError error = objectErrors.get(i);
errorCodes[i] = error.getCode();
}
return errorCodes;
}
use of org.springframework.validation.ObjectError in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method extractMethodArgumentNotValidExceptionBindingResultErrors.
@Test
public void extractMethodArgumentNotValidExceptionBindingResultErrors() throws Exception {
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new MethodArgumentNotValidException(null, bindingResult);
testBindingResult(bindingResult, ex);
}
use of org.springframework.validation.ObjectError in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method extractBindingResultErrors.
@Test
public void extractBindingResultErrors() throws Exception {
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new BindException(bindingResult);
testBindingResult(bindingResult, ex);
}
Aggregations