-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug
Milestone
Description
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):
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate()).addNode("fieldToMarkAsInvalid").addConstraintViolation();
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:
Object invalidValue = 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);
} else if (cd instanceof ConstraintDescriptorImpl) {
ConstraintDescriptorImpl<?> cdImpl = (ConstraintDescriptorImpl<?>) cd;
if (cdImpl.getElementType().equals(ElementType.TYPE)) {
BeanWrapperImpl beanWrapper = new BeanWrapperImpl(invalidValue);
invalidValue = beanWrapper.getPropertyValue(field);
}
}
in
protected void processConstraintViolations(Set<ConstraintViolation<Object>> violations, Errors errors)
Affects: 3.2.1
Issue Links:
- GenericConversionService.convert() throws IllegalArgumentException after updating to Spring 3.2.1 [SPR-10243] #14876 GenericConversionService.convert() throws IllegalArgumentException after updating to Spring 3.2.1
Metadata
Metadata
Assignees
Labels
in: webIssues in web modules (web, webmvc, webflux, websocket)Issues in web modules (web, webmvc, webflux, websocket)type: bugA general bugA general bug