Record Mapping Strategy for OpenCSV

This site utilizes Google Analytics, Google AdSense, as well as participates in affiliate partnerships with various companies including Amazon. Please view the privacy policy for more details.

I’ve deployed yet another artifact to Maven Central - this time a record mapping strategy that allows you to read and write Java Record Classes with OpenCSV.

As always, I have the code on GitHub.

And here’s the dependency information for a Maven POM file:


And here’s a repeat of the README file:

Record Mapping Strategy for OpenCSV

A record mapping strategy that allows OpenCSV to read and write Java Records.

How to use

To read from a CSV:

var fileReader = new FileReader("myRecord.csv");

var csvReader = new CSVReader(fileReader);

var csvToBeanBuilder = new CsvToBeanBuilder<MyRecord>(csvReader)
        .withMappingStrategy(new RecordMappingStrategy<>(MyRecord.class));

var actualList =;


To write to a CSV:

var fileWriter = new FileWriter("myRecord.csv");

var csvWriter = new StatefulBeanToCsvBuilder<MyRecord>(fileWriter)
    .withMappingStrategy(new RecordMappingStrategy<>(MyRecord.class))


// If using a FileWriter, don't forget to close it otherwise Java might
// not finish writing to the file.

Why use RecordMappingStrategy to write?

Why not just use HeaderColumnNameMappingStrategy, which RecordMappingStrategy extends?

HeaderColumnNameMappingStrategy makes the column headers all-caps, which is okay until you try to read the CSV file.

Leave a Reply

Note that comments won't appear until approved.