Using JAXB to unmarshal/marshal a List<String> - Inheritance

Posted by gerry on Stack Overflow See other posts from Stack Overflow or by gerry
Published on 2010-03-15T10:55:36Z Indexed on 2010/03/15 10:59 UTC
Read the original article Hit count: 796

Filed under:
|
|

I've build the following case. An interface for all JAXBLists:

public interface JaxbList<T> {
public abstract List<T> getList();
}

And an base implementation:

@XmlRootElement(name="list")
public class JaxbBaseList<T> implements JaxbList<T>{
    protected List<T> list;

    public JaxbBaseList(){}

    public JaxbBaseList(List<T> list){
        this.list=list;
    }

    @XmlElement(name="item" )
    public List<T> getList(){
        return list;
    }
}

As well as an implementation for a list of URIs:

@XmlRootElement(name="uris")
public class JaxbUriList2 extends JaxbBaseList<String> {

    public JaxbUriList2() { super();    }
    public JaxbUriList2(List<String> list){
        super(list);
    }


    @Override
    @XmlElement(name="uri")
    public List<String> getList() {
        return list;
    }
}

And I'm using the List in the following way:

public JaxbList<String> init(@QueryParam("amount") int amount){

        List<String> entityList = new Vector<String>();
        ...
        enityList.add("http://uri");
    ...
        return new JaxbUriList2(entityList);
    }

I thought the output should be:

<uris>
<uri>
http://uri
</uri>
...
</uris>

But it is something like this:

<uris>
<item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">
http://uri
</item>
...
<uri>
http://uri
</uri>
...
</uris>

I think it has something to do with the inheritance, but I don't get it...

What's the problem? - How can I fix it?

Thanks in advance!

© Stack Overflow or respective owner

Related posts about java

Related posts about jaxb