You're right, using <list> instead of <value> for the headerLines property solves the problem.
Before:
Code:
<bean id="myFlatFileWriter"
class="org.springframework.batch.item.file.FlatFileItemWriter">
<property name="resource" value="file:target/test-outputs/my-data.csv" />
<property name="headerLines" value="ITEM_NO,ITEM_NAME" />
<property name="fieldSetCreator" ref="myFieldSetCreator" />
</bean>
The headerLines property value is interpreted as a String[] and is split into two lines, which results in this incorrect my-date.csv file:
Code:
ITEM_NO
ITEM_NAME
00012345,Some text
After:
Code:
<bean id="myFlatFileWriter"
class="org.springframework.batch.item.file.FlatFileItemWriter">
<property name="resource" value="file:target/test-outputs/my-data.csv" />
<property name="headerLines">
<list>
<value>ITEM_NO,ITEM_NAME</value>
</list>
</property>
<property name="fieldSetCreator" ref="myFieldSetCreator" />
</bean>
The headerLines property value is interpreted as a List and is kept as a single line, which results in this my-date.csv file:
Code:
ITEM_NO,ITEM_NAME
00012345,Some text
It was not immediately obvious, at least not to me. Even though the headerLines property is of type List, the only setter for headerLines takes a String[]. I guess Spring does some property setting magic under the covers.