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,

1
  • It doesn't work with @Range. The error is: javax.validation.UnexpectedTypeException: No validator could be found for type: java.util.List<java.lang.Integer> Commented Jan 16, 2011 at 5:50

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.