Unable to get Jaxb2Marhshaller to create indented xml
Hi,
I'm writing a batch process to transform an xml file into another xml format, and trying to set up the Jaxb2Marshaller to output the xml in indented format, to make it easier to read and verify.
Now the problem is JAXB_FORMATTED_OUTPUT doesn't seem to get set in the context, even though I'm passing in the value of "true" using "marshallerProperties" property.
I've tried using the latest version of Jaxb2Marshaller in spring-oxm-tiger-1.5.6.jar but it still doesn't work. :mad:
I've included a snippet of the context file that I'm using. I've tried to make it complete as possible because I don't know if there are any interactions between the different beans that I'm not aware of.
<bean id="tm" class="org.springframework.batch.support.transacti on.ResourcelessTransactionManager"/>
<bean id="jobRepository" class="org.springframework.batch.core.repository.s upport.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="tm"/>
</bean>
<bean id="helloStep" class="org.springframework.batch.core.step.item.Si mpleStepFactoryBean">
<property name="transactionManager" ref="tm"/>
<property name="jobRepository" ref="jobRepository"/>
<property name="itemReader" ref="reader"/>
<property name="itemWriter" ref="transformingWriter"/>
<!--need to register the xmlWriter directly because we are using ItemTransformerItemWriter-->
<!--see: forum.springframework.org/showthread.php?t=63297-->
<property name="streams">
<list>
<ref bean="xmlWriter" />
</list>
</property>
</bean>
<bean id="transformingWriter" class="org.springframework.batch.item.transform.It emTransformerItemWriter">
<property name="itemTransformer" ref="mapper" />
<property name="delegate" ref="xmlWriter"/>
</bean>
<bean id="xmlWriter" class="org.springframework.batch.item.xml.StaxEven tItemWriter">
<property name="rootTagName" value="JOBS"/>
<property name="serializer" ref="xmlSerializer"/>
<property name="overwriteOutput" value="true"/>
<property name="resource" ref="xmlOutputFile"/>
</bean>
<bean id="xmlSerializer" class="org.springframework.batch.item.xml.oxm.Mars hallingEventWriterSerializer">
<constructor-arg index="0" ref="jaxbMarshaller" />
</bean>
<!--TODO - can we config this so that it outputs in indented format-->
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
<property name="contextPath" value="our.package"/>
<property name="marshallerProperties">
<map>
<!--TODO - why is this not working?? -->
<entry>
<key>
<util:constant static-field="javax.xml.bind.Marshaller.JAXB_FORMATTED_OU TPUT" />
</key>
<value type="boolean">true</value>
</entry>
</map>
</property>
</bean>
Does anyone have an idea of what is the correct config that works? I've Googled around for examples on doing this, and it seems that I'm using the right settings, but it doesnt seem to affect the formatting of the xml. The xml gets marshalled, and the output file is created, but it's just not indented.
thanks,
Ellecer