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,
The isEmpty() method of List interface in java is used to check if a list is empty or not. It returns true if the list contains no elements otherwise it returns false if the list contains any element.
The @Valid annotation ensures the validation of the whole object. Importantly, it performs the validation of the whole object graph. However, this creates issues for scenarios needing only partial validation. On the other hand, we can use @Validated for group validation, including the above partial validation.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With