Reputation: 21
I am using a sping ws endpoint with jaxb marshalling/unmarshalling to proudce a list of Organisation
objects (our local type). The endpoint is SOAP 1.1, no parameters supplied on the request message.
I understand JAXB doesn't handle lists very well, so I use a wrapper class.
@XmlRootElement(name="orgResponse", namespace=....)
public class OrganisationListWrapper {
private ArrayList<Organisation> organisationList;
public getOrganisationList() {
return organisationList;
}
public setOrganisationList(ArrayList<Organisation> organisationList) {
this.organisationList = organisationList;
}
}
The endpoint....
@PayloadRoot(localPart=.... namespace=....)
@ResponsePayload
public OrganisationListWrapper getOrganisations() {
OrganisationListWrapper wrapper = new OrganisationListWrapper();
wrapper.setOrganisationList(.... call service layer get list ....);
return wrapper;
}
This works fine and I get a SOAP payload with
<orgResponse>
<organisationList>
... contents of organisation 1
</organisationList>
<organisationList>
... comtents of organisation 2
</organisationList>
.... etc ....
</orgResponse>
The Organisation class is not JAXB annotated. It is part of a large list of pre-existing classes that are being exposed through web services for the first time. Trying to get by without going in and annotating them all by hand.
I was able to override the name OrganisationWrapper
with orgResponse
in the XmlRootElement
annotation. I would like to override the organisationList
name in the child element with organisation
but haven't been able to find an annotation that does this.
I can replace the array list name with organisation
and it will work fine, but our coding standard here required us to put List
on the end of our list names. I would like to try and stick to that. I have tried XmlElement
, but that produced a jaxb exception.
Any suggestions would be appreciated.
Upvotes: 2
Views: 1832
Reputation: 149017
Because JAXB default the access type to PUBLIC_MEMBER, make sure you annotate the property (getter) and not the field:
@XmlElement(name="organisation")
public getOrganisationList() {
return organisationList;
}
If you want to annotate the field then add the following annotation to your class:
@XmlAccessorType(XmlAccessType.FIELD)
Upvotes: 1