Why doesn't the @NotNull constraint on a1 ever get enforced?
Is it really never or is it not validated only if the constraint on a2 is violated? Validation of group sequences stops after the first erroneous group. So if your default group sequence is defined as Complete, A, validation will stop after Complete if a2 is invalid.
I don't think there's any way to actually achieve what I want since there doesn't seem to be any way to invoke validation such that only the constraint on a1 is enforced
Your use case can be implemented using group inheritance. Define two groups like so:
public interface Relaxed {}
public interface Complete extends Relaxed, javax.validation.groups.Default {}
Redeclare the default group sequence for A so it as Complete as the first element:
@GroupSequence({Complete.class, SuperUser.class})
public class A {
@NotNull(groups=Relaxed.class)
public String a1;
@NotNull
public String a2;
}
Then when validating the default group (by passing no group at all or Default.class to the validate() call), it will validate the Complete group which comprises all the constraints from Default and Relaxed. When calling validate(new A(), Relaxed.class), it'll only validate the constraint on a1. Hope that helps - please let me know when we can close this issue. Thanks! |