我正在维护一些复杂的 Java 代码,并且 Castor (v1.2) 解组非常慢,因为有很多“丢失”的 Java 对象。看,XML 包含的字段比我需要的要多,但 Castor 反复尝试实例化 Java 对象,导致很多 ClassNotFound 错误。
脚轮映射文件:
<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 等效项,我不希望它解组。我尝试org.exolab.castor.xml.strictelements=false
在 castor.properties 文件中进行设置,但这并不能阻止它通过类加载路径并引发 ClassNotFound 错误。
如何让 Castor 跳过不需要的 XML 元素?