如何让 Castor 忽略某些 XML 字段?
我正在维护一些复杂的 Java 代码,并且由于相当多的“丢失”Java 对象,Castor (v1.2) 解组非常慢。看,XML 包含的字段比我需要的多,但 Castor 反复尝试实例化 Java 对象,导致大量 ClassNotFound 错误。
Castor 映射文件:
<mapping>
<class name="com.example.imaging.product.Product">
<map-to xml="product"/>
<field name="productId" type="long">
<bind-xml name="id" node="attribute"/>
</field>
</class>
<class name="com.example.imaging.product.RegionConfiguration">
<map-to xml="mediaConfiguration"/>
<field name="name" type="string">
<bind-xml name="name" node="attribute"/>
</field>
<field name="design" type="int">
<bind-xml name="designId" node="attribute"/>
</field>
</class>
</mapping>
XML 来源:
<?xml version="1.0"?>
<product id="1234">
<productImage colorId="1"/>
<mediaConfiguration name="Front" designId="98765" />
<color id="1" name="Red" default="true"/>
</product>
我的问题是 color
字段没有 Java 等效字段,并且我不希望对其进行解组。我尝试在castor.properties 文件中设置org.exolab.castor.xml.strictelements=false,但这并不能阻止它遍历类加载路径并引发ClassNotFound 错误。
如何让 Castor 跳过不需要的 XML 元素?
I am maintaining some complex Java code and the Castor (v1.2) unmarshaling is very slow due to quite a few "missing" Java objects. See, the XML contains more fields than I require but Castor repeatedly tries to instantiate the Java objects, causing lots of ClassNotFound errors.
Castor Mapping File:
<mapping>
<class name="com.example.imaging.product.Product">
<map-to xml="product"/>
<field name="productId" type="long">
<bind-xml name="id" node="attribute"/>
</field>
</class>
<class name="com.example.imaging.product.RegionConfiguration">
<map-to xml="mediaConfiguration"/>
<field name="name" type="string">
<bind-xml name="name" node="attribute"/>
</field>
<field name="design" type="int">
<bind-xml name="designId" node="attribute"/>
</field>
</class>
</mapping>
XML Source:
<?xml version="1.0"?>
<product id="1234">
<productImage colorId="1"/>
<mediaConfiguration name="Front" designId="98765" />
<color id="1" name="Red" default="true"/>
</product>
My problem is that the color
field doesn't have a Java equivalent and I don't want it unmarshaled. I tried setting org.exolab.castor.xml.strictelements=false
in the castor.properties file but that doesn't keep it from walking the classload path and throwing ClassNotFound errors.
How can I make Castor skip over non-needed XML elements?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您无法覆盖尝试解组每个元素的行为,请参阅 Castor 参考。您是否衡量过真正的性能影响是什么?在 Castor 开发出更好的覆盖行为之前,最好忽略这一点。
It sounds like you can't override the behavior of trying to unmarshal each element, see the Castor reference. Have you measured what the real performance impact is? It might be best just to ignore this until Castor develops better override behavior.