title: How do we do kotlin data class validation on Collection?
body: <p>I am trying to add validation to my data models in kotlin, The simple fields are easy to do using the <code>@field</code> annotations. But, I am struggling to do the same with collections. </p>
  
  <p>I have uploaded the issue to github <a href="https://github.com/SachinPuthran/kotlin-data-validation.git" rel="noreferrer">here</a> </p>
  
  <p>The java model is working with no issues but the kotlin version is not. I am adding both the models here.</p>
  
  <pre><code>public class JavaUser {
      @NotEmpty
      @NotNull
      @Pattern(regexp = "[a-z]*", message = "Only lower case first name")
      private String name;
  
      private List&lt;
              @NotNull
              @NotEmpty
              @Pattern(regexp = "\\d{10}", message = "Only 10 digits")
                      String&gt; phones;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public List&lt;String&gt; getPhones() {
          return phones;
      }
  
      public void setPhones(List&lt;String&gt; phones) {
          this.phones = phones;
      }
  }
  </code></pre>
  
  <pre><code>data class KotlinUser(
      @field:NotEmpty
      @field:NotNull
      @field:Pattern(regexp = "[a-z]*", message = "Only lower case first name")
      val name: String,
  
      // Cannot use @field here, anything else we could use?
      val phones: List&lt;
          @NotNull
          @NotEmpty
          @Pattern(regexp = "\\d{10}", message = "Only 10 digits")
          String&gt;
  )
  </code></pre>
  
  <p>My tests - The java test passes but the kotlin one fails</p>
  
  <pre><code>    @Test
      fun `java user validation`() {
          val javaUser = JavaUser()
          javaUser.name = "sadfjsjdfhsjdf"
          javaUser.phones = listOf("dfhgd")
  
          webTestClient.put().uri("/user/java")
              .body(BodyInserters.fromObject(javaUser))
              .exchange()
              .expectStatus().is4xxClientError
      }
  
      @Test
      fun `kotlin user validation`() {
          val kotlinUser = KotlinUser(name = "sadfjsjdfhsjdf", phones = listOf("dfhgd"))
  
          webTestClient.put().uri("/user/kotlin")
              .body(BodyInserters.fromObject(kotlinUser))
              .exchange()
              .expectStatus().is4xxClientError
      }
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>@RestController
  class Controller {
      @PutMapping("/user/java")
      fun putUser(@RequestBody @Valid javaUser: JavaUser): Mono&lt;ResponseEntity&lt;String&gt;&gt; =
          Mono.just(ResponseEntity("shouldn't get this", HttpStatus.OK))
  
      @PutMapping("/user/kotlin")
      fun putUser(@RequestBody @Valid kotlinUser: KotlinUser): Mono&lt;ResponseEntity&lt;String&gt;&gt; =
          Mono.just(ResponseEntity("shouldn't get this", HttpStatus.OK))
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated. Thank you!</p>