/spring-batch-extensions

CSV record line compensation for Spring Batch

Primary LanguageJavaApache License 2.0Apache-2.0

spring-batch-extensions for CSV file format

Build Status

Spring Batch extension provides compensation for some Comma Separated Values (CSV) errors like missing escape and/or quote characters. The compensation rules do roughly follow the ideas of Libre Office module.

Implementation can be used for

  • Spring Batch 3
  • Java 5

Example

"begin;'abc' d 'ef';end"
=>
"begin;'abc'' d ''ef';end"

For a more complete list of test cases, please refer to unit tests in FixingCsvRecordSeparatorPolicyTest.

A more detailed discussion about specific cases and the implementation used for Libre Office can be found on bugs.freedesktop.org.

Usage

Inject the Separator Policy implementation into FlatFileItemReader using the setter setRecordSeparatorPolicy. See Spring Batch Java Doc for details.

<bean class="org.springframework.batch.item.file.FlatFileItemReader">
    <property name="recordSeparatorPolicy">
        <bean class="de.mediait.batch.FixingCsvRecordSeparatorPolicy">
        </bean>
    </property>
    ...
</bean>