我正在将项目从版本 1.x 升级到 jaxb 2.2.7。
我的应用程序有时可以运行,但在一些回复中我看到了这一点:
java.lang.RuntimeException: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: Instance of "com.mycompany.global.er.decoupling.binding.response.PricePointType$BalanceImpactRates$BalanceImpactRate"
is substituting "java.lang.Object", but
"com.mycompany.global.er.decoupling.binding.response.PricePointType$BalanceImpactRates$BalanceImpactRate"
is bound to an anonymous type.]
这在 jaxb 1.0 中运行良好。我不知道问题是什么。
这是 xsd 的摘录(我无法更改,因为客户正在使用它):
<xs:complexType name="price-pointType">
<xs:sequence>
<xs:element name="id" type="xs:string" />
.........
<xs:element name="duration" type="durationType" />
<xs:element name="order" type="xs:int" />
<xs:element name="min-sub-period" type="xs:int" />
<xs:element name="balance-impacts" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="balance-impact" type="charging-resourceType"
minOccurs="0" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="balance-impact-rates" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="balance-impact-rate" minOccurs="0"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="rate" type="xs:double" />
</xs:sequence>
<xs:attribute name="charging-resource-code" type="xs:string"
use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
有什么建议么?
问题原来是匿名复杂类型的精心嵌套。
通过如下将它们分开,问题就消失了。作为额外的好处,我获得了更多可重用的代码。
<xs:complexType name="balanceImpactRate">
<xs:sequence>
<xs:element name="rate" type="xs:double" />
</xs:sequence>
<xs:attribute name="charging-resource-code" type="xs:string"
use="required" />
</xs:complexType>
<xs:complexType name="balanceImpactRates" >
<xs:sequence>
<xs:element name="balance-impact-rate" type="balanceImpactRate" minOccurs="0"
maxOccurs="unbounded">
</xs:element>
</xs:sequence>
</xs:complexType>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)