'Convert CSV data to JSON POJO for large file
I am using CsvMapper to convert a CSV file to a list of POJO JSON objects for potentially large files.
byte [] csvData ...
CsvMapper csvMapper = new CsvMapper()
...
CsvSchema csvSchema = csvMapper
.schemaFor(MyPojo.class)
.withHeader();
MappingIterator<MyPojo> mappedLines = csvMapper.readerFor(MyPojo.class)
.with(csvSchema)
.readValues(csvData);
mappedLines.forEachRemaining(myPojo -> doSomeAction(myPojo));
This reads all the values to a MappingIterator.
Is it possible to only read one record at a time and then doSomeAction? (to minimize the memory utilisation for very large CSV files)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
