0

I'm working on a batch using spring-batch with one reader, one writer ,one processor. I have one CSV file as an input of my reader.

I wanted to use OpenCSV to convert one line to one bean but what i see from the documentation is that OpenCsv take one file and use the object CsvToBeanBuilder to map all the line of one file to a list of object.

I saw this post : Configuring openCSV instead of FlatFileItemReader in spring batch step

but there is no explanation on how to map one String line to a Bean object using opencsv. Do someone know if it's possible? thanks.

1 Answers1

0

The explanation is in the comments. OpenCSV does the reading and the mapping. If you want to use OpenCSV in your Spring Batch app with a FlatFileItemReader, you only need the mapping part, ie a LineMapper implementation based on OpenCSV.

Now if OpenCSV does not provide a way to map a single line to a POJO, then it is probably not suitable to be used in Spring Batch in that way. In that case, you need to implement a custom ItemReader based on OpenCSV that does the reading and the mapping.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50