If domain object level validation constraint is specified and some custom validator marks explicitly an object field as invalid (instead of default global object):
SpringValidatorAdapter doesn't check for this option and creates FieldError for marked field but rejected value is not field value but domain object itselves. Think this is a bug. For now I use this fix, but I'm not sure if this covers all possible cases:
ObjectinvalidValue = violation.getInvalidValue();
if (field.contains(".") && !field.contains("[]")) {
// Possibly a bean constraint with property path: retrieve the actual property value.// However, explicitly avoid this for "address[]" style paths that we can't handle.invalidValue = bindingResult.getRawFieldValue(field);
} elseif (cdinstanceofConstraintDescriptorImpl) {
ConstraintDescriptorImpl<?> cdImpl = (ConstraintDescriptorImpl<?>) cd;
if (cdImpl.getElementType().equals(ElementType.TYPE)) {
BeanWrapperImplbeanWrapper = newBeanWrapperImpl(invalidValue);
invalidValue = beanWrapper.getPropertyValue(field);
}
}
Pavla Nováková opened SPR-10345 and commented
If domain object level validation constraint is specified and some custom validator marks explicitly an object field as invalid (instead of default global object):
SpringValidatorAdapter doesn't check for this option and creates FieldError for marked field but rejected value is not field value but domain object itselves. Think this is a bug. For now I use this fix, but I'm not sure if this covers all possible cases:
in
Affects: 3.2.1
Issue Links:
The text was updated successfully, but these errors were encountered: