| In https://hibernate.atlassian.net/browse/BVAL-638 I had a discussion with Gunnar Morling regarding a requirement to be able to specify a particular group when performing validation that selects contraints that are not explcitly assigned to a group. This is to allow for relaxing constraints is specific circumstances while having default evaluation execute all constraints by default. For example: In the class
public class A {
@NotNull
public String a1;
@NotNull
public String a2;
}
I would like a way to express that by default all constraints should be validated but in particular validation points only a subset of these constraints be validated. I want to be able to do this by adjusting the annotation only on those constraints that are to be relaxed.
As suggested by Gunnar, one approach is to introduce some ALL_UNASSIGNED pre-defined group then have the following, for example, if I want to be able to relax the constraint on a2.
public interface Complete extends Default {}; @GroupSequence( {Complete.class, A.class}) public class A { @NotNull public String a1; @NotNull(groups={Complete.class}) public String a2; }
In this case, default validation will enforce the constraints on a1 and a2 but evaluation against ALL_UNASSIGNED would only evaluate the constraint on a1.
It would also be useful to be able to specify specific constraints that are only evaluated in the relaxed case for example:
public interface Complete extends Default {}; public interface Partial extends {}; @GroupSequence({Complete.class, A.class} ) public class A { @NotNull public String a1; @NotNull(groups= {Complete.class}) public String a2; @NotNull(groups={Complete.class} ) @Null(groups={Partial.class}}) public String a3 }
validator.validate(instanceOfA, Partial.class, ALL_UNASSIGNED)
then the @Null constraint on a3 would be enforced but not otherwise. I think that would just work in the presence of an ALL_UNASSIGNED special validation group. |