Conditional validation of bean in a list field.
I have a little problem with bean validation. I would like to do a conditional validation, but the validated class have as a field a list of bean which must be also validated, and some of these bean's fields must be conditionally validated.
Here is my code :
public class ParentBean {
@Valid
private List<ChildBean> childBeans;
}
public class ChildBean {
boolean flag;
@NotNull(condition="flag")
String mustNotBeNullFlagTrue;
String cannotBeNull();
}
I could do a loop on the child beans and validate each child separitively but the path in the errors would be wrong
Addittionnaly, I could use a solution like this one : Cross field validation with Hibernate Validator (JSR 303) but it seems to mess up with the path associated to the error...