How to make Castor ignore some XML fields?

I support some complex Java code, and Castor (v1.2) parsing is very slow due to the many β€œmissing” Java objects. See, XML contains more fields than I need, but Castor repeatedly tries to instantiate Java objects, causing a lot of ClassNotFound errors.

Castor Map 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 there is no Java equivalent in the color field, and I don't want it to be unmarshaled. I tried to set org.exolab.castor.xml.strictelements=false in the castor.properties file, but that does not stop him from walking the class path and throwing ClassNotFound errors.

How can I make Castor skip unnecessary XML elements?

+4
source share
1 answer

It looks like you cannot override the behavior of trying to untie each element, see Castor link . Did you rate the real impact on performance? It is best to ignore this until Castor improves on behavior other than overriding.

If the class is not described in the mapping file, Castor will expose the class to 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 an XML element / attribute named "xxx-yyy". In the future, we will provide the ability to override this default behavior.

0
source

All Articles