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.
我正在维护一些复杂的Java代码,并且由于相当多的“缺失”Java对象,Castor(v1.2)解编非常慢。请注意,XML包含的字段比我要求的多,但Castor反复尝试实例化Java对象,从而导致大量的ClassNotFound错误。
Castor Mapping File:
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 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.
我的问题是颜色字段没有Java等价物,我不希望它被解组。我尝试在castor.properties文件中设置org.exolab.castor.xml.strictelements = false,但这并不妨碍它走掉classload路径并抛出ClassNotFound错误。
How can I make Castor skip over non-needed XML elements?
如何让Castor跳过不需要的XML元素?
1 个解决方案
#1
0
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.
听起来你无法覆盖尝试解组每个元素的行为,请参阅Castor参考。您是否测量过真正的性能影响?在Castor开发更好的覆盖行为之前,最好忽略这一点。
If the class is not described in the mapping file, Castor will instrospect the class using the Java Reflection API to determine if there is any function of the form getXxxYyy()/setXxxYyy( x). This accessor will be associated with XML element/attribute named 'xxx-yyy'. In the future, we will provide a way to override this default behavior.
如果映射文件中没有描述该类,Castor将使用Java Reflection API对该类进行检查,以确定是否存在getXxxYyy()/ setXxxYyy(x)形式的任何函数。此访问器将与名为“xxx-yyy”的XML元素/属性相关联。将来,我们将提供一种覆盖此默认行为的方法。
#1
0
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.
听起来你无法覆盖尝试解组每个元素的行为,请参阅Castor参考。您是否测量过真正的性能影响?在Castor开发更好的覆盖行为之前,最好忽略这一点。
If the class is not described in the mapping file, Castor will instrospect the class using the Java Reflection API to determine if there is any function of the form getXxxYyy()/setXxxYyy( x). This accessor will be associated with XML element/attribute named 'xxx-yyy'. In the future, we will provide a way to override this default behavior.
如果映射文件中没有描述该类,Castor将使用Java Reflection API对该类进行检查,以确定是否存在getXxxYyy()/ setXxxYyy(x)形式的任何函数。此访问器将与名为“xxx-yyy”的XML元素/属性相关联。将来,我们将提供一种覆盖此默认行为的方法。