I am trying to understand the Groups in Bean validation.
So for instance if I have a bean and I want only certain field validated for certain cases, I should group them?
@NotNull (groups=MyClassX.class)
@Min (groups=MyClassA.class) // 1
@Pattern(xxxxx, groups = MyClassA.class) // 2
private String field1;
@NotNull (groups=MyClassX.class)
@Min (groups=MyClassX.class)
@Pattern(xxxxx, groups=MyClassX.class))
private String field2;
@NotNull (groups=MyClassX.class)
@Min (groups=MyClassX.class)
@Pattern(xxxxx, groups=MyClassA.class) //3
private String field3;
My understanding from the above example is, if I pass MyClassA
to validator, then only @Min
and @Pattern
for Field1
and @Pattern
for field3
are only validated? (marked with numbers 1,2 and 3)
Did I understand this correctly?
I haven't left any fields without Groups
attribute. So no default group.