gpt4 book ai didi

java - com.sun.istack.SAXException2 : Instance . .. 正在替换 "java.lang.Object",但是 ... 绑定(bind)到匿名类型

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:17:43 24 4
gpt4 key购买 nike

我正在将一个项目从版本 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>

关于java - com.sun.istack.SAXException2 : Instance . .. 正在替换 "java.lang.Object",但是 ... 绑定(bind)到匿名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21117879/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com