Jemolah
Jemolah

Reputation: 2192

Java Bean Validation: How do I specify multiple validation constraints of the same type but with different groups?

I have multiple processes in which the bean properties must have different values. Example:

@Min( value=0, groups=ProcessA.class )
@Min( value=20, groups=ProcessB.class )
private int temperature;

Unfortunately the bean validation JSR 303 has not set @Repeatable on javax.validation.constraints.Min so this approach does not work. I found "Min.List" but without any doc about how to use it. Instead the official Oracle doc states at http://docs.oracle.com/javaee/7/api/javax/validation/constraints/class-use/Min.List.html

No usage of javax.validation.constraints.Min.List

So at moment this looks like a specification error?!?

Upvotes: 10

Views: 5649

Answers (1)

JB Nizet
JB Nizet

Reputation: 691645

The syntax for Min.List, as for any other annotation taking an array of annotations as one of its attributes, is

@Min.List({ @Min(value = 0, groups = ProcessA.class),
            @Min(value = 20, groups = ProcessB.class) })

Upvotes: 12

Related Questions