Announcement Announcement Module
Collapse
No announcement yet.
How to avoid splitting headerLines? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to avoid splitting headerLines?

    I want to write a CSV file using FlatFileItemWriter, but my headerLines property ("ITEM_NO,ITEM_NAME") gets split into two header lines. I want them to be a single line.

    It's the default String array propertyeditor that does it, I guess. How can I avoid this? Can I access the registrar and remove this particular editor?

    I'm using 1.1.4.

  • #2
    You should be able to set the property as an explicit <list><value>...</value></list> - that way the property editor will not try and convert the value.

    Comment


    • #3
      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.

      Comment

      Working...
      X