Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?!?

like image 510
Jemolah Avatar asked Apr 07 '15 21:04

Jemolah


1 Answers

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) })
like image 105
JB Nizet Avatar answered Oct 12 '22 23:10

JB Nizet