title: How to use @ConvertGroup with @GroupSequenceProvider
body: <p>I'm trying to use <code>@ConvertGroup</code> for some cascading validation with my spring boot project but it does not seem to work. Can anyone tell me what i am doing wrong?</p>
  
  <p>I've created a trimmed down project for this question. </p>
  
  <p>You can check it out here:
  <a href="https://github.com/ericbv/cascadingValidationConvertGroupSpringBoot" rel="nofollow noreferrer">https://github.com/ericbv/cascadingValidationConvertGroupSpringBoot</a></p>
  
  <p>I have the following DTOs for the form:</p>
  
  <p>The Parent Dto</p>
  
  <pre><code>@GroupSequenceProvider(ParentGroupSequenceProvider.class)
  public class ParentDto {
  
      @Valid
      @ConvertGroup(from= CreateChild.class , to = Creation.class)
      private ChildDto childDto;
  
      private boolean createChild;
  
      public ChildDto getChildDto() {
          return childDto;
      }
  
      public void setChildDto(ChildDto childDto) {
          this.childDto = childDto;
      }
  
      public boolean isCreateChild() {
          return createChild;
      }
  
      public void setCreateChild(boolean createChild) {
          this.createChild = createChild;
      }
  }
  </code></pre>
  
  <p>From my understanding the ConvertGroup annotation should pass The CreationGroup in the child validation if the CreateGroup Group is present while validating the parent. (this group will be provided by the ParentGroupSequenceProvider.</p>
  
  <p>And the child object:</p>
  
  <pre><code>public class ChildDto {
      @NotEmpty(groups = Creation.class)
      private String name;
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  }
  </code></pre>
  
  <p>If the Creation group is present the name cannot be null. I've tested this by adding <code>@GroupSequence({ChildDto.class,Creation.class})</code> to the top of this class this resulted in a Validation error.</p>
  
  <p>The Parent DTO has the folowing Group sequence provider:</p>
  
  <pre><code>public class ParentGroupSequenceProvider implements DefaultGroupSequenceProvider&lt;ParentDto&gt; {
  
      static Logger log = Logger.getLogger(ParentGroupSequenceProvider.class.getName());
      @Override
      public List&lt;Class&lt;?&gt;&gt; getValidationGroups(ParentDto parentDto) {
          List&lt;Class&lt;?&gt;&gt; sequence = new ArrayList&lt;Class&lt;?&gt;&gt;();
  
        /*
         * must be added to the returned list so that the validator gets to know
         * the default validation rules, at the very least.
         */
          sequence.add(ParentDto.class);
  
          if (parentDto == null)
              return sequence;
        /*
         *  Here, we can implement a certain logic to determine what are the additional group of rules
         *  that must be applied.
         */
          if(parentDto.isCreateChild()){
              sequence.add(CreateChild.class);
              log.info("Added CreateChild to groups");
  
          }
  
          return sequence;
      }
  }
  </code></pre>
  
  <p>This sequence provider will add the creatChild group if the creation boolean is true.</p>
  
  <p>I did test the groupSequenceProvider by adding a string property to the parentDto with the <code>@NotEmpty(groups = CreateChild.class)</code>. This threw a validation error so I know the group is provided.</p>
  
  <p>The controller mehtod:</p>
  
  <pre><code>@RequestMapping(value = "/test",method = RequestMethod.POST)
  public String doPost(@Valid ParentDto parentDto, BindingResult bindingResult){
      if(bindingResult.hasErrors()){
          bindingResult.getAllErrors().forEach( error-&gt; log.error(error));
          return "redirect: /error";
      }else{
          return "redirect: /";
      }
  
  }
  </code></pre>
  
  <p>The problem is when the form submits and createChild is true the name property in the childDto is not validated.</p>
  
  <p>What did i miss?</p>
  
  <p>Pom file below:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.test&lt;/groupId&gt;
      &lt;artifactId&gt;valid-testing&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;valid-testing&lt;/name&gt;
      &lt;description&gt;Demo project for Spring Boot&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;1.3.1.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-embed-el&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  
  &lt;/project&gt;
  </code></pre>