Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing JAXB to unmarshal/marshal a List<String> - Inheritance
    text
    copied!<p>I've build the following case. An interface for all JAXBLists:</p> <pre><code>public interface JaxbList&lt;T&gt; { public abstract List&lt;T&gt; getList(); } </code></pre> <p>And an base implementation:</p> <pre><code>@XmlRootElement(name="list") public class JaxbBaseList&lt;T&gt; implements JaxbList&lt;T&gt;{ protected List&lt;T&gt; list; public JaxbBaseList(){} public JaxbBaseList(List&lt;T&gt; list){ this.list=list; } @XmlElement(name="item" ) public List&lt;T&gt; getList(){ return list; } } </code></pre> <p>As well as an implementation for a list of URIs:</p> <pre><code>@XmlRootElement(name="uris") public class JaxbUriList2 extends JaxbBaseList&lt;String&gt; { public JaxbUriList2() { super(); } public JaxbUriList2(List&lt;String&gt; list){ super(list); } @Override @XmlElement(name="uri") public List&lt;String&gt; getList() { return list; } } </code></pre> <p>And I'm using the List in the following way:</p> <pre><code>public JaxbList&lt;String&gt; init(@QueryParam("amount") int amount){ List&lt;String&gt; entityList = new Vector&lt;String&gt;(); ... enityList.add("http://uri"); ... return new JaxbUriList2(entityList); } </code></pre> <p>I thought the output should be:</p> <pre><code>&lt;uris&gt; &lt;uri&gt; http://uri &lt;/uri&gt; ... &lt;/uris&gt; </code></pre> <p>But it is something like this:</p> <pre><code>&lt;uris&gt; &lt;item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string"&gt; http://uri &lt;/item&gt; ... &lt;uri&gt; http://uri &lt;/uri&gt; ... &lt;/uris&gt; </code></pre> <p>I think it has something to do with the inheritance, but I don't get it...</p> <p>What's the problem? - How can I fix it?</p> <p>Thanks in advance!</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