JAXB / JAXWS, generics and inheritance

I create a SOAP WebService when I use the following classes:

Firstly, I have an abstract and general class:

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

Then I have two classes that inherit the type transfer as a 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 that I use wsimport to create a client for my WS, the created CollaboratorPaginatedList and GenericUserPaginatedList do not have their own list with the corresponding type. I checked in WSDL / XSD and I see that there is a list of objects and I don’t understand why.

Can you help me please? And is there a way to get JAXB to enter a list?

Thanks:)

PS: I tried @XmlElementWrapper with shared list and inheritance

============= My answer is because I am a beginner and I can not answer my question :)

I found a workaround, but for me it is not very clean. Firstly, I saw this link in the corresponding section

Creating an abstract jaxb generic class

Parent abstract class:

 @XmlType @XmlAccessorType(XmlAccessType.FIELD) public abstract class PaginatatedListContainer<T> { public abstract List<T> getElements(); public abstract void setElements(List<T> elements); } 

Children's 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 XSD / WSDL, I have what I want because of @XmlElement in typed lists, and not because of abstract getter / setter.

+4
source share

Source: https://habr.com/ru/post/1488635/


All Articles