title: JAXB converts @XmlElementRefs and @XmlElements to xs:choice
body: <p>I have 4 classes. <code>Person</code> class, and abstract <code>ContactInformation</code> with <code>Phone</code> and <code>Address</code> class extending it.</p>
  
  <pre><code>@XmlRootElement
  @XmlAccessorType(XmlAccessType.NONE)
  public class Person {
      @XmlElement(required = true, nillable = false)
      private String first;
      @XmlElement(required = true, nillable = false)
      private String last;
      @XmlElementWrapper(name = "contacts")
      @XmlElementRefs({
          @XmlElementRef(name = "phone", type = Phone.class, required = true),
          @XmlElementRef(name = "address", type = Address.class, required = true)
      })
      private final List&lt;ContactInfomation&gt; contacts = new ArrayList&lt;&gt;();
  }
  </code></pre>
  
  <p><code>ContactInformation</code> is used only as container:</p>
  
  <pre><code>public abstract class ContactInfomation { /* empty class */ }
  </code></pre>
  
  <p><code>Phone</code> class:</p>
  
  <pre><code>@XmlRootElement
  @XmlAccessorType(XmlAccessType.NONE)
  public class Phone extends ContactInfomation {
      @XmlElement(required = true, nillable = false)
      private String number;
  }
  </code></pre>
  
  <p>And <code>Address</code> class:</p>
  
  <pre><code>@XmlRootElement
  @XmlAccessorType(XmlAccessType.NONE)
  public class Address extends ContactInfomation {
      @XmlElement(required = true, nillable = false)
      private String country;
      @XmlElement(required = true, nillable = false)
      private String city;
  }
  </code></pre>
  
  <p>The problem is when I change <code>@XmlElementrefs</code> to <code>@XmlElements</code> in <code>Person</code> class, nothing happens. <code>JAXB</code> maps them to <code>xs:choice</code>. The XML output is same as before and <code>schemagen</code> generates the same schema as before.
  Here is a sample output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;person&gt;
      &lt;first&gt;majid&lt;/first&gt;
      &lt;last&gt;azimi&lt;/last&gt;
      &lt;contacts&gt;
          &lt;address&gt;
              &lt;country&gt;US&lt;/country&gt;
              &lt;city&gt;Los Angles&lt;/city&gt;
          &lt;/address&gt;
          &lt;address&gt;
              &lt;country&gt;US&lt;/country&gt;
              &lt;city&gt;New York&lt;/city&gt;
          &lt;/address&gt;
          &lt;phone&gt;
              &lt;number&gt;5551037&lt;/number&gt;
          &lt;/phone&gt;
      &lt;/contacts&gt;
  &lt;/person&gt;
  </code></pre>
  
  <p>And here is the schema:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  
    &lt;xs:element name="address" type="address"/&gt;
  
    &lt;xs:element name="person" type="person"/&gt;
  
    &lt;xs:element name="phone" type="phone"/&gt;
  
    &lt;xs:complexType name="person"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element name="first" type="xs:string"/&gt;
        &lt;xs:element name="last" type="xs:string"/&gt;
        &lt;xs:element name="contacts" minOccurs="0"&gt;
          &lt;xs:complexType&gt;
            &lt;xs:sequence&gt;
              &lt;xs:choice minOccurs="0" maxOccurs="unbounded"&gt;
                &lt;xs:element ref="phone"/&gt;
                &lt;xs:element ref="address"/&gt;
              &lt;/xs:choice&gt;
            &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
        &lt;/xs:element&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  
    &lt;xs:complexType name="phone"&gt;
      &lt;xs:complexContent&gt;
        &lt;xs:extension base="contactInfomation"&gt;
          &lt;xs:sequence&gt;
            &lt;xs:element name="number" type="xs:string"/&gt;
          &lt;/xs:sequence&gt;
        &lt;/xs:extension&gt;
      &lt;/xs:complexContent&gt;
    &lt;/xs:complexType&gt;
  
    &lt;xs:complexType name="contactInfomation" abstract="true"&gt;
      &lt;xs:sequence/&gt;
    &lt;/xs:complexType&gt;
  
    &lt;xs:complexType name="address"&gt;
      &lt;xs:complexContent&gt;
        &lt;xs:extension base="contactInfomation"&gt;
          &lt;xs:sequence&gt;
            &lt;xs:element name="country" type="xs:string"/&gt;
            &lt;xs:element name="city" type="xs:string"/&gt;
          &lt;/xs:sequence&gt;
        &lt;/xs:extension&gt;
      &lt;/xs:complexContent&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Documentation of <code>@XmlElementRef</code> uses it for Substitution group and XML choice. I'm completely confused what is the difference of <code>@XmlElementRefs</code>/<code>@XmlElementRef</code> and <code>@XmlElements</code>/<code>@XmlElement</code>. Can anyone help?</p>