spring ws jaxb注释更改xml元素名称
我使用带有 jaxb 编组/解组的 sping ws 端点来生成 Organization
对象(我们的本地类型)列表。端点是 SOAP 1.1,请求消息中未提供任何参数。
我知道 JAXB 不能很好地处理列表,因此我使用包装类。
@XmlRootElement(name="orgResponse", namespace=....)
public class OrganisationListWrapper {
private ArrayList<Organisation> organisationList;
public getOrganisationList() {
return organisationList;
}
public setOrganisationList(ArrayList<Organisation> organisationList) {
this.organisationList = organisationList;
}
}
端点....
@PayloadRoot(localPart=.... namespace=....)
@ResponsePayload
public OrganisationListWrapper getOrganisations() {
OrganisationListWrapper wrapper = new OrganisationListWrapper();
wrapper.setOrganisationList(.... call service layer get list ....);
return wrapper;
}
这工作正常,我得到一个 SOAP 有效负载,其中
<orgResponse>
<organisationList>
... contents of organisation 1
</organisationList>
<organisationList>
... comtents of organisation 2
</organisationList>
.... etc ....
</orgResponse>
Organization 类没有 JAXB 注释。它是首次通过 Web 服务公开的大量预先存在的类的一部分。试着不去手工注释它们。
我能够使用 XmlRootElement
注释中的 orgResponse
覆盖名称 OrganizationWrapper
。我想用 organization
覆盖子元素中的 organizationList
名称,但无法找到执行此操作的注释。
我可以用 organization
替换数组列表名称,它会正常工作,但我们的编码标准要求我们将 List
放在列表名称的末尾。我想尝试并坚持下去。我尝试过 XmlElement
,但这产生了 jaxb 异常。
任何建议将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为 JAXB 默认访问类型为 PUBLIC_MEMBER,所以请确保您注释属性(getter)而不是字段:
如果您想注释字段,则将以下注释添加到您的类中:
Because JAXB default the access type to PUBLIC_MEMBER, make sure you annotate the property (getter) and not the field:
If you want to annotate the field then add the following annotation to your class: