title: Transformation of generic classes to XML Schema for Java web services
body: <p>In my application I have many tables with pagination, so I created a class to hold the partial list of results and the total number of results for a paginated query:</p>
  
  <pre><code>@XmlRootElement(name = "paginatedList")
  public class PaginatedList&lt;T&gt; implements Serializable {
      private List&lt;T&gt; results;
      private Integer totalSize;
  
      @XmlElement(name = "result")
      public List&lt;T&gt; getResults() {
          return this.results;
      }
  
      @XmlElement(name = "totalSize")
      public int getTotalSize() {
          return totalSize;
      }
  
      // Setters, constructors, etc.
  }
  </code></pre>
  
  <p>Then I expose the following method to an EJB:</p>
  
  <pre><code>PaginatedList&lt;EmployeeType&gt; getPaginatedList();
  </code></pre>
  
  <p>Additionally, I expose this method with a Web service. But the generated XSD for the web service response loses the type information (<code>EmployeeType</code>):</p>
  
  <pre><code>&lt;xs:complexType name="getPaginatedListResponse"&gt;
      &lt;xs:sequence&gt;
         &lt;xs:element name="return" type="tns:paginatedList" minOccurs="0"/&gt;
      &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  &lt;xs:complexType name="paginatedList"&gt;
      &lt;xs:sequence&gt;
         &lt;xs:element name="result" type="xs:anyType" minOccurs="0" maxOccurs="unbounded"/&gt;
         &lt;xs:element name="totalSize" type="xs:int"/&gt;
      &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  </code></pre>
  
  <p>I understand that this may happen because of type erasure, but if I return just the list as below:</p>
  
  <pre><code>List&lt;EmployeeType&gt; getList();
  </code></pre>
  
  <p>I get a much better XSD:</p>
  
  <pre><code>&lt;xs:complexType name="getListResponse"&gt;
      &lt;xs:sequence&gt;
          &lt;xs:element name="return" type="tns:employeeType" minOccurs="0" maxOccurs="unbounded"/&gt;
      &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  
  &lt;xs:complexType name="employeeType"&gt;
      &lt;xs:sequence&gt;
          &lt;xs:element name="id" type="xs:int" minOccurs="0"/&gt;
          &lt;xs:element name="name" type="xs:string" minOccurs="0"/&gt;
      &lt;/xs:sequence&gt;
  &lt;/xs:complexType&gt;
  </code></pre>
  
  <p>So the question is this: What should I do in order not to lose the type information from the response of my web service? Is there any JAXB magic I should do in order to "simulate" the XSD generation of List. Any recommendations are welcome.</p>
  
  <p>If it makes any difference, I'm using Weblogic 10.3 to deploy my project. </p>