title: How to validate the size of @RequestParam of type List
body: <p>I'm creating a Spring-Boot microservice REST API that expects <code>@RequestParam</code> of type <code>List&lt;String&gt;</code>. How can I validate that the list contains a minimum and a maximum amount of values?</p>
  
  <p>So far I've tried using <code>@Size(min=1, max=2)</code> which is supposed to support collections as well (<code>javax.validation.constraints.Size</code>).</p>
  
  <p>I also tried adding <code>@Valid</code> and a <code>BindingResult</code> parameter along with the <code>@Size</code> annotation without success.</p>
  
  <p>I'd prefer using a solution similar to the first example using <code>@Size(min=1, max=2)</code> which is more compact and neat. This is for Spring-Boot 2.1.2.RELEASE.</p>
  
  <pre><code>@RestController
  public class MyApi {
  
      @GetMapping(value = "/myApi", produces = { APPLICATION_JSON_VALUE })
      public ResponseEntity&lt;List&lt;MyObject&gt;&gt; getSomething(@Valid @RequestParam(value = "programEndTime", required = false) @Size(min = 1, max = 2) List&lt;String&gt; programEndTime, BindingResult result) {
          if (result.hasErrors()) {
              System.out.println("Error");
          } else {
              System.out.println("OK");
          }
      }
  }
  </code></pre>
  
  <p>I expect the <code>System.out.println("Error")</code> line to be reached but it's actually skipped.</p>