Validator.validate method that calls nested class validate() gets wrong object in childs error.entity validation [SPR-13245] #17836
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: bulk-closed
An outdated, unresolved issue that's closed in bulk as part of a cleaning process
Bruce Edge opened SPR-13245 and commented
I'm implementing a Validator for a class with a nested array of children objects and the child validator is failing because the context in which the child validator runs contains the parent's reference in the Error.entity instead of the child's.
I'm following the docs here: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html
My data model, a parent Collection object with a child Collectionitem list.
My Collection parent and CollectionItem child validators:
The problem is that when the child items array is validated and CollectionItemValidator.validate() is called for each ColectionItem by ValidationUtils.invokeValidator(collectionItemValidator...) , the Error e.entity passed into the child validator is a still the parent Collection, not the child CollectionItem object, so the check for a "title" field always fails because ValidationUtils.rejectIfEmpty is looking at the parent rather than the child object in the errors.getFieldValue(field);:
is using the parent Collection object in the errors.getFieldValue(), so it never finds the field as only the child has a "title" field, the parent does not.
Note that the ValidationUtils
has the right obj in the args, the problem is that the errors.entity is never updated to point to the child element.
Affects: 4.2 RC2
1 votes, 2 watchers
The text was updated successfully, but these errors were encountered: