4

I am creating a SOAP WebService when I use following classes:

First, I have an abstract and generic class:

@XmlTransient
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class PaginatatedListContainer<T> {
@XmlElement
protected List<T> elements;

    ...getter and setter
}

Then, I have two classes which inherits passing a type as class parameter

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class CollaboratorPaginatedList extends PaginatedListContainer<Collaborator> {
}

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class GenericUserPaginatedList extends PaginatedListContainer<GenericUser> {
}

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.

Can you help me understand, please? And is there a way to force JAXB to type the list?

Thank you :)

PS: I tried @XmlElementWrapper with a generic List and inheritance

============ My answer because I am new and I can't answer my own question :)

I found a workaround but to me, it is not very clean. First, I saw this link in the related section

Creating abstract generic jaxb class

The parent abstract class:

@XmlType
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class PaginatatedListContainer<T> {

    public abstract List<T> getElements();
    public abstract void setElements(List<T> elements);

}

The children classes:

@XmlType
public class CollaboratorPaginatedList extends PaginatedListContainer<Collaborator> {

    @XmlElement
    private List<Collaborator> collaborators;

... reimplemented getter/setter
}

@XmlType
public class GenericUserPaginatedList extends PaginatedListContainer<GenericUser> {

    @XmlElement
    private List<GenericUser> collaborators;

... reimplemented getter/setter
}

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.

Community
  • 1
  • 1
tlegrand
  • 776
  • 1
  • 8
  • 14

0 Answers0