6

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,

Sean Nguyen
  • 11,700
  • 20
  • 69
  • 109
  • It doesn't work with @Range. The error is: javax.validation.UnexpectedTypeException: No validator could be found for type: java.util.List – Sean Nguyen Jan 16 '11 at 05:50

1 Answers1

1

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

Zilvinas
  • 5,319
  • 3
  • 23
  • 26