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

I have several 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, bean JSR 303 validation did not set @Repeatable to javax.validation.constraints.Min, so this approach does not work. I found "Min.List", but without any document on how to use it. Instead, an Oracle white paper claims that http://docs.oracle.com/javaee/7/api/javax/validation/constraints/class-use/Min.List.html

Using javax.validation.constraints.Min.List

So at the moment it looks like a specification error?!?

+6
source share
1 answer

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

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

Source: https://habr.com/ru/post/984819/


All Articles