ValidationResult Class — spring-boot Architecture
Architecture documentation for the ValidationResult class in ValidationBindHandler.java from the spring-boot codebase.
Entity Profile
Relationship Graph
Source Code
core/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/validation/ValidationBindHandler.java lines 154–254
private class ValidationResult extends BeanPropertyBindingResult {
private final ConfigurationPropertyName name;
protected ValidationResult(ConfigurationPropertyName name, Object target) {
super(target, "");
this.name = name;
}
@Override
public String getObjectName() {
return this.name.toString();
}
@Override
public @Nullable Class<?> getFieldType(@Nullable String field) {
ResolvableType type = getBoundField(ValidationBindHandler.this.boundTypes, field);
Class<?> resolved = (type != null) ? type.resolve() : null;
if (resolved != null) {
return resolved;
}
return super.getFieldType(field);
}
@Override
protected @Nullable Object getActualFieldValue(String field) {
Object boundField = getBoundField(ValidationBindHandler.this.boundResults, field);
if (boundField != null) {
return boundField;
}
try {
return super.getActualFieldValue(field);
}
catch (Exception ex) {
if (isPropertyNotReadable(ex)) {
return null;
}
throw ex;
}
}
private boolean isPropertyNotReadable(Throwable ex) {
while (ex != null) {
if (ex instanceof NotReadablePropertyException) {
return true;
}
ex = ex.getCause();
}
return false;
}
private <T> @Nullable T getBoundField(Map<ConfigurationPropertyName, T> boundFields, @Nullable String field) {
if (field == null) {
return null;
}
try {
ConfigurationPropertyName name = getName(field);
T bound = boundFields.get(name);
if (bound != null) {
return bound;
}
if (name.hasIndexedElement()) {
for (Map.Entry<ConfigurationPropertyName, T> entry : boundFields.entrySet()) {
if (isFieldNameMatch(entry.getKey(), name)) {
return entry.getValue();
}
}
}
}
catch (Exception ex) {
// Ignore
}
return null;
}
private boolean isFieldNameMatch(ConfigurationPropertyName name, ConfigurationPropertyName fieldName) {
if (name.getNumberOfElements() != fieldName.getNumberOfElements()) {
return false;
}
for (int i = 0; i < name.getNumberOfElements(); i++) {
String element = name.getElement(i, Form.ORIGINAL);
String fieldElement = fieldName.getElement(i, Form.ORIGINAL);
if (!ObjectUtils.nullSafeEquals(element, fieldElement)) {
return false;
}
}
return true;
}
private ConfigurationPropertyName getName(String field) {
return this.name.append(DataObjectPropertyName.toDashedForm(field));
}
ValidationErrors getValidationErrors() {
Set<ConfigurationProperty> boundProperties = ValidationBindHandler.this.boundProperties.stream()
.filter((property) -> this.name.isAncestorOf(property.getName()))
.collect(Collectors.toCollection(LinkedHashSet::new));
return new ValidationErrors(this.name, boundProperties, getAllErrors());
}
}
Domain
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free