Note that there are some explanatory texts on larger screens.

plurals
  1. POJAXB/JAXWS, Generics And Inheritance
    text
    copied!<p>I am creating a SOAP WebService when I use following classes:</p> <p>First, I have an abstract and generic class:</p> <pre><code>@XmlTransient @XmlAccessorType(XmlAccessType.FIELD) public abstract class PaginatatedListContainer&lt;T&gt; { @XmlElement protected List&lt;T&gt; elements; ...getter and setter } </code></pre> <p>Then, I have two classes which inherits passing a type as class parameter</p> <pre><code>@XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class CollaboratorPaginatedList extends PaginatedListContainer&lt;Collaborator&gt; { } @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class GenericUserPaginatedList extends PaginatedListContainer&lt;GenericUser&gt; { } </code></pre> <p>My problem is when I use wsimport to generate the client of my WS, the generated CollaboratorPaginatedList and GenericUserPaginatedList do not have their own list with the proper type. I verified in the WSDL/XSD and I see there is an object list instead and I don't understand why.</p> <p>Can you help me understand, please? And is there a way to force JAXB to type the list?</p> <p>Thank you :)</p> <p>PS: I tried <a href="https://stackoverflow.com/questions/9911444/xmlelementwrapper-with-a-generic-list-and-inheritance">@XmlElementWrapper with a generic List and inheritance</a></p> <p>============ My answer because I am new and I can't answer my own question :)</p> <p>I found a workaround but to me, it is not very clean. First, I saw this link in the related section</p> <p><a href="https://stackoverflow.com/questions/13244652/creating-abstract-generic-jaxb-class?rq=1">Creating abstract generic jaxb class</a></p> <p>The parent abstract class:</p> <pre><code>@XmlType @XmlAccessorType(XmlAccessType.FIELD) public abstract class PaginatatedListContainer&lt;T&gt; { public abstract List&lt;T&gt; getElements(); public abstract void setElements(List&lt;T&gt; elements); } </code></pre> <p>The children classes:</p> <pre><code>@XmlType public class CollaboratorPaginatedList extends PaginatedListContainer&lt;Collaborator&gt; { @XmlElement private List&lt;Collaborator&gt; collaborators; ... reimplemented getter/setter } @XmlType public class GenericUserPaginatedList extends PaginatedListContainer&lt;GenericUser&gt; { @XmlElement private List&lt;GenericUser&gt; collaborators; ... reimplemented getter/setter } </code></pre> <p>In fact, in the XSD/WSDL, I have what I want because of the @XmlElement on the typed lists and not because of the abstract getter/setter.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload