title: How to validate a collection in spring-mvc POST webservice?
body: <p>I have a simple <code>spring</code> webservice that offers a <code>@PostMapping</code> and takes a json array of elements.
  I want spring to automatically validate each element in the list.</p>
  
  <pre><code>@RestController
  public class PersonServlet {
      @PostMapping
      public void insertPersons(@RequestBody @Valid List&lt;PersonDto&gt; array) {
      }
  }
  
  
  public class PersonDto {
      @NotBlank
      private String firstname;
  
      @NotBlank
      private String lastname;
  }
  </code></pre>
  
  <p>The following <code>POST</code> request should fail with a validation error that <code>firstname</code> is missing:</p>
  
  <pre><code>[
    {
      "lastname": "john"
  
    },
    {
      "firstname": "jane",
      "lastname": "doe"
    }
  ]
  </code></pre>
  
  <p>Result: the request is NOT rejected. Why?</p>
  
  <p>Sidenote: if I just use <code>PersonDto</code> as parameter (not a list), and send a <code>json</code> post request with only one persons, the validation works and correctly rejects the request.</p>
  
  <p>So in general the validation annotations seem to work, but just not when inside the collection!</p>