Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSR Bean Validation and multiple groups, AND vs OR

Has anyone come across the need to have a constraint that is only applied when all group clauses are satisfied. In other words, for

@NotNull(groups= {Group1.class, Group2.class})
private Integer value;

The not null constraint is applied when either group is valid.

What if I want to apply a constraint when both groups are valid?

Having a custom group is not an option as there are many combinations of such groups in my application.

like image 293
Ashkan Aryan Avatar asked Oct 09 '22 09:10

Ashkan Aryan


1 Answers

You might declare a group sequence containing all your groups and validate that sequence.

like image 61
Gunnar Avatar answered Oct 12 '22 10:10

Gunnar