Results 1 to 3 of 3

Thread: How to avoid splitting headerLines?

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default 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.
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

  2. #2
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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.

  3. #3
    Join Date
    Jul 2005
    Location
    Helsingborg, Sweden
    Posts
    504

    Default

    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.
    Ulrik Sandberg
    Jayway (www.jayway.com)
    Spring LDAP project member

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •