Search code examples
springspring-batchcastorspring-batch-adminspring-oxm

Setting castor properties using Spring Oxm


Spring Oxm allows you to use different marshallers/unmarshallers and Castor is one of them.

By default castor marshalles xml documents unindented and official documents tell that putting a castor.properties file in the search locations including the line org.exolab.castor.indent=true will override the default behavior.

Now, when using Spring Oxm in a web application (Spring Batch Admin) how can I override the castor.properties in the castor jar?

I have the following bean configurations (extra lines removed) and they do not have the necessary properties to set for this as far as I can see.

<bean id="myCastorMarshaller" 
    class="org.springframework.oxm.castor.CastorMarshaller">
<property name="mappingLocation" value="classpath:/mapping/my-mapping.xml" />
</bean>

<bean id="myXmlWriter" 
   class="org.springframework.batch.item.xml.StaxEventItemWriter">
<property name="marshaller" ref="myCastorMarshaller" />
</bean>

Solution

  • Answering my own question: Using Spring 3.1.2 there is no solution for this question.

    The class org.springframework.oxm.castor.CastorMarshaller should be in charge for setting properties and it has even jira issue for this SPR-8470 but the patches are not committed to main branch after more than a year.

    Anyone may compare CastorMarshaller at Github with the proposed patch.

    In brief, we need a setProperties(...) method in the CastorMarshaller but the patch is not committed.