XML should be readable for humans. Therefore you will have to print XML output with correct indentation and line breaks.
JAXB is not doing so by default, also not using Spring.
In order to enable so called pretty printing for XML files generated using JAXB, you will have to modify the context.xml in your Java Spring project.
Juat add the following to the bean definition for the JAXB Marshaller in your projects Spring context.xml.
Below is an example for an
ItemWriter, which sets the marshallers property "
jaxb.formatted.output" to true.
However this will cause the JAXB marshaller to indent your XML, Spring Batch will ruin it again by encapsulating it with a
I found following solution on stackoverflow.com to work for me.
First you will have to add the following dependency to your pom.xml.
I could not get one artifact, the stax-utils depend on in the company artifactory so I just downloaded the jar from the artifactory and included it in the build path of my project.
Then I was able to override the
StaxEventItemWriter with an implementation that just delegates the writing to a stax-utils class called
Last but not least you have to update the
ItemWriter defined in the Spring Batch XML context to something like the following.
Pretty much effort, just to make it readable!
The "util" prefix in above "constant" tag definition refers to the following XML namespace.
Hope it helps.