Validate field / property constraints before class level constraint is validated.
Currently class level constraints are validated before single field constraints by default. This requires us to repeat some validation in the class level constraint like checking for null values.
*Improvement*
A bean is never valid if any single field is invalid. In other words, it is a precondition that all fields must be valid so that a class level constraint can be valid.
Following example would throw a NPE in the `isValid` method, since `@NotNull` on property `value` was not evaluated before `@FooValidator`
{code:java} @FooValidator public class Foo { @NotNull private String value;
private String property; }
/* * Validate that setting of <code>property</code> is only valid if <code>value</code> equals "test" */ public class FooValidator { @Override public boolean isValid(final Foo foo, final ConstraintValidatorContext context) { if (!value.equals("test") && property != null) return false; } } {code}
*Related SO questions* * http://stackoverflow.com/questions/30431293/how-to-validate-field-level-constraint-before-class-level-constraint * http://stackoverflow.com/questions/10380209/java-bean-validation-groupsequence-with-class-level-constraint?rq=1 |
|