I'm using univocity parsers with BeanListProcessor to map to my Java Bean which is good provided the column names don't change. However, I also need to parse a csv file which comes with different columns for each type of user. I have the mappings stored for each user to my standard column names, but how do I parse it dynamically to my pojo without having to modify the file. I couldnt use HeaderTransformer since its still not dynamic. Please let me know if you need additional info. The version I'm using is 2.6.3
For example:
BeanListProcessor<MyPojo> rowProcessor = new BeanListProcessor<MyPojo>(MyPojo.class);
CsvParserSettings parserSettings = new CsvParserSettings();
parserSettings.setProcessor(rowProcessor);
parserSettings.setHeaderExtractionEnabled(true);
CsvParser parser = new CsvParser(parserSettings);
parser.parse(getReader(file));
List<MyPojo> pojos= rowProcessor.getBeans();
pojos.forEach(v -> System.out.println(v.toString()));
public class MyPojo{
@Trim
@Parsed
private String myColumn1;
@Trim
@Parsed
private String myColumn2;
....
User1 file:
user1Column,user2Column\n
data1,data2
User 1 mappings
user1Column -> myColumn1
user2Column -> myColumn2