title: Javax validation on nested objects - not working
body: <p>In my Spring Boot project I have two DTO's which I'm trying to validate, LocationDto and BuildingDto. The LocationDto has a nested object of type BuildingDto.</p>
  
  <p>These are my DTO's:</p>
  
  <p><strong>LocationDto</strong></p>
  
  <pre><code>public class LocationDto {
  
    @NotNull(groups = { Existing.class })
    @Null(groups = { New.class })
    @Getter
    @Setter
    private Integer id;
  
    @NotNull(groups = { New.class, Existing.class })
    @Getter
    @Setter
    private String name;
  
    @NotNull(groups = { New.class, Existing.class, LocationGroup.class })
    @Getter
    @Setter
    private BuildingDto building;
  
    @NotNull(groups = { Existing.class })
    @Getter
    @Setter
    private Integer lockVersion;
  
  }
  </code></pre>
  
  <p><strong>BuildingDto</strong></p>
  
  <pre><code>public class BuildingDto {
  
    @NotNull(groups = { Existing.class, LocationGroup.class })
    @Null(groups = { New.class })
    @Getter
    @Setter
    private Integer id;
  
    @NotNull(groups = { New.class, Existing.class })
    @Getter
    @Setter
    private String name;
  
    @NotNull(groups = { Existing.class })
    @Getter
    @Setter
    private List&lt;LocationDto&gt; locations;
  
    @NotNull(groups = { Existing.class })
    @Getter
    @Setter
    private Integer lockVersion;
  
  }
  </code></pre>
  
  <p>Currently, I can validate in my <code>LocationDto</code> that the properties <code>name</code> and <code>building</code> are not null, but <strong>I can't validate the presence of the property id which is inside building</strong>.</p>
  
  <p>If I use the <code>@Valid</code> annotation on the <code>building</code> property, it would validate all of its fields, but for this case I only want to validate its <code>id</code>.</p>
  
  <p>How could that be done using javax validation?</p>
  
  <p>This is my controller:</p>
  
  <pre><code>@PostMapping
  public LocationDto createLocation(@Validated({ New.class, LocationGroup.class }) @RequestBody LocationDto location) {
    // save entity here...
  }
  </code></pre>
  
  <p>This is a correct request body: (should not throw validation errors)</p>
  
  <pre><code>{
    "name": "Room 44",
    "building": {
      "id": 1
    }
  }
  </code></pre>
  
  <p>This is an incorrect request body: (must throw validation errors because the <strong><em>building id is missing</em></strong>)</p>
  
  <pre><code>{
    "name": "Room 44",
    "building": { }
  }
  </code></pre>