Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSR303 validation on collection of common objects

Is it possible to validate each element of a collection, based one or more delegate validation rules? For example:

@EachElement({@Min(1), @Max(12)})
private Set<Integer> monthNumbers;
like image 208
Jeroen Avatar asked Aug 25 '11 07:08

Jeroen


1 Answers

Take a look at validator-collection, with this library is very easy to use any Constraint Annotation on a collection of simple types.

@EachMin(1)
@EachMax(12)
private Set<Integer> monthNumbers;

Also see https://stackoverflow.com/a/16023061/2217862.

like image 142
Jakub Jirutka Avatar answered Oct 08 '22 11:10

Jakub Jirutka