1

I want to use an annotation to limit the maximum length of the list to 10. I'm using the @Max annotation, but it doesn't work. Is there any way to do this?

@Max(value = 10)
private List<String> ipRange;
g00glen00b
  • 41,995
  • 13
  • 95
  • 133

1 Answers1

0

You must use the @size annotation as follow @size(max = 10) because it is the right annotation to check size of lists as reported in the javadoc:

Size range for Arrays, Collections or Maps

Instead the annotation @max must be used to restrict range of numeric values, not sizes of item containers:

max restriction on a numeric annotated element

Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56
  • Okay, I also used the size annotation at first, but then I looked at the Controller layer methods and found that they were not marked with the Validated annotation. Now the problem is solved. Thanks. – user19774005 Aug 30 '22 at 05:45