在我的一个项目中,我使用jaxb2 marshaller,使用契约优先的web服务,我从xml模式生成对象。
一切正常。但是,我有一个“代码可用性”的问题。我给你举个例子。
架构:
<xs:complexType name="personContractAlertListType">
<xs:sequence>
<xs:element ref="PersonContractAlert" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="PersonContractAlertsResponse">
<xs:complexType>
<xs:sequence>
<xs:element ref="PersonContractAlertList"/>
</xs:sequence>
</xs:complexType>
</xs:element>
所以为了访问
PersonContractAlerts
我得打电话给:
PersonContractAlertsResponse.getPersonContractAlertListType().getPersonContractAlert()
有点长。
我的问题是:我怎样才能摆脱
getPersonContractAlertListType()
直接转到:
PersonContractAlertsResponse.getPersonContractAlert()
因为包装器元素实际上只用于xsd,所以我的java对象中不需要它。
换句话说,有:
<Element1>
<Wrapper>
<Element2/>
</Wrapper>
</Element1>
我希望它在Java中映射到:
Element1.getElement2()
可能使用jaxb适配器。记住我不想碰生成的对象。这必须在marshaller设置(adapter、interceptor等)或xsd中完成(可能有一些设置需要操作)。
谢谢!
更新:
我找到了一些绑定操作的教程:
https://jaxb.dev.java.net/guide/Using_different_datatypes.html
我将研究尝试使用jaxb绑定。