title: JAXB schema to Java Different XmlRootElement name and Class name
body: <p>I have a xsd schema from which I'm generating some java classes. I'm using jaxb for the generation.</p>
  
  <p>I want to be able to generate a class annotated with <code>@XmlRootElement</code>, but I want the @XmlRootElement name property to be different than the name of the generated class.</p>
  
  <p>In my xsd I'm defining the following:</p>
  
  <pre><code>&lt;xs:element name="customer"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
           ....
          &lt;/xs:sequence&gt;
       &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>This piece of code generates the following java class:</p>
  
  <pre><code>@XmlRootElement(name = "customer")
  public class Customer {
  ...
  }
  </code></pre>
  
  <p>The name property of the <code>@XmlRootElement</code> is the same as the name of the generated Class. I want the generated class name to be <code>CustomerReques</code>t.</p>
  
  <p>I've tryed to use the <code>jaxb:class</code> definition to change the classe name. Indeed this option changes the class name but removes the <code>@XmlRootElement</code> annotation, and I need it to be present.</p>
  
  <p>The following xsd:</p>
  
  <pre><code>&lt;xs:element name="customer"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:annotation&gt;
                  &lt;xs:appinfo&gt;
                      &lt;jaxb:class name="CustomerRequest"/&gt;
                  &lt;/xs:appinfo&gt;
              &lt;/xs:annotation&gt;
          &lt;xs:sequence&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>
  
  <p>Generates this class:</p>
  
  <pre><code>@XmlAccessorType(XmlAccessType.FIELD)
  @XmlType(name = "customer", propOrder = {
  
  })
  public class CustomerRequest {
  }
  </code></pre>
  
  <p>How can I make the property name of the <code>@XmlRootElement</code> annotation different from the generated class name without loosing the annotation?</p>
  
  <p><strong>Solution update:</strong>
  User Xstian proposed the correct solution using external bindings.
  Just for further reference, I'll update my own post with the solution converted for using inline bindings:</p>
  
  <pre><code> &lt;xs:element name="customer"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:annotation&gt;
                  &lt;xs:documentation&gt;Request object for the operation that checks if a customer profile exists.&lt;/xs:documentation&gt;
                  &lt;xs:appinfo&gt;
                          &lt;annox:annotate&gt;
                              &lt;annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement" name="customer"/&gt;
                          &lt;/annox:annotate&gt;
                          &lt;jaxb:class name="CustomerRequest"/&gt;
                      &lt;/xs:appinfo&gt;
                  &lt;/xs:annotation&gt;
              &lt;xs:sequence&gt;
              &lt;/xs:sequece&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  </code></pre>