title: Spring validation with inheritance
body: <p>I'm trying to validate a DTO (formModel, whatever term you prefer) which is a bit layered (inheritance and dependencies to other classes).</p>
  
  <p>Is it possible to get the following configuration of models to work:</p>
  
  <pre><code>public abstract class A {
  
      @NotNull
      private String fieldA1;
  
      @NotNull
      @Size(min = 2, max = 30)
      private String fieldA2;
  
      // ... and so on
  
  }
  
  
  public class B extends A {
  
      @NotNull
      private String fieldB1;
  
      @NotNull
      private Xyz fieldB2;
  
      // and so on
  }
  
  
  public class Xyz {
  
      @NotNull
      private String fieldXyz1;
  
      // etc..
  }
  </code></pre>
  
  <p>Spring rest controller:</p>
  
  <pre><code>@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity addCustomer(@RequestBody @Valid B customerDto, BindingResult bindingResult) {
  // controller logic here
  }
  </code></pre>
  
  <p>The problem is: only constraint annotations that seem to "work" are those on the parent class A. I submit a request with bad fields in the class A, <code>bindingResult.hasErrors()</code> returns true. If I submit a request with bad fields in classes B or Xyz, <code>bindingResult.hasErrors()</code> is false and the controller just goes on behaving like the request is ok. 
  Any ideas why?</p>