Validate field / property constraint before class level constraint

Description

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`

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 @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; } }

Related SO questions

Environment

None

Status

Assignee

Unassigned

Reporter

Marco Janc

Labels

None

Worked in

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Community Help Wanted

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Components

Priority

Major