Skip to content
Advertisement

Reading line breaks in CSV which are quoted in the file in FlatfileItemReader of spring batch

I am trying to parse a CSV file with FlatFileItemReader. This CSV contains some quoted newline characters as shown below.

JavaScript

But this parsing is failing with required fields are 2 but actual is 1.

What I am missing in my FlatFileReader configuration?

JavaScript

Advertisement

Answer

out of the box the FlatFileItemReader uses a SimpleRecordSeparatorPolicy, for your usecase

  • commented part goes over 2 or more lines

you need to set the DefaultRecordSeparatorPolicy

Cited from its javadoc:

A RecordSeparatorPolicy that treats all lines as record endings, as long as they do not have unterminated quotes, and do not end in a continuation marker.

example xml configuration

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement