Reputation: 13128
I have a list of integer like this:
private List<Integer> indexes;
Is there a way to valid individual member to be in a range of 0-9? I see @Range and @Valid but can't find a way to make it work with List.
Thanks for your help,
Upvotes: 6
Views: 1457
Reputation: 5578
Only @Size and @Valid can be used on Collections, however you can use some wrapper object instead of "Integer" to validate your ints, e.g.:
public class Index {
@Range( min = 0, max = 9 )
private Integer value;
}
public class Container {
@Valid
private List<Index> indexes;
}
This should do the trick
Upvotes: 1