Announcement Announcement Module
Collapse
No announcement yet.
Reading Flat file with Different Columns When generated Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Reading Flat file with Different Columns When generated

    Hi, I am using spring batch to read a flat file generated from a third party. However the depending on the input the flat file which is tab delimited can have different columns so for example 1 file could have

    col 1 /t col2 /t col3 /t col4 /t col5 and another one could have col 1 /t col2 /t col3 /t col 3a /t col 3b /t col4 /t col5. There will only ever be a max of 5 cols but minimum could be 1.

    I have looked through the docs and am using the flat file item reader not a custom one. I have the following names in the line mapper but is there a way to dynamically change this field set. to cope with more columns. Would that be the correct way to go about it?

    In the docs 6.6.2.7. Automapping FieldSets to Domain Objects could i potentially use this automapping function to get around this? In my names property in my context I could specify all the possible columns and then the automapping would do its magic???? Welcome any suggestions.

    thanks



    Code:
    <beans:bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
    						<beans:property name="delimiter">
    						    <util:constant static-field="org.springframework.batch.item.file.transform.DelimitedLineTokenizer.DELIMITER_TAB"/>
    						</beans:property>
    						<beans:property name="names" value="ID,lastName,firstName,position,birthYear,debutYear" />
    					</beans:bean>

  • #2
    In case anyone has similar issue I resolved this by reading the first line of the file to determine the headers then used late binding to bind the names to the reader.

    Comment

    Working...
    X