Hello,
I am using two types of constraints: field and class constraints, and I want to run the field constraints first. Since there is not a predefined order for these constraints, I need to create an sequence. Is there a way to create this order without specifying a group for the field or class constraints? Is there a predefined "group" for class constraints?
Another thing that I would like to know is if there is a way to control the flow of the sequence. If the field validations fail I don't want to run the class validations. I don't want to replicate validation code, e.g. check if fields are null.
A simple example of this:
Code:
@CheckMyClass
public class MyClass {
@NotNull
private Long longA;
@NotNull
private Long longB;
}
The validator checks if longA is less than longB, otherwise will fail the validation. I don't want to check for nulls again:
Code:
public class CheckMyClassValidator {
(...)
public boolean isValid(MyClass myClass, ConstraintValidatorContext constraintValidatorContext) {
if(myClass.getLongA() < myClass.getLongB()){
return true;
}
else {
return false;
}
}
}