csv to bean , excluding the values not included in csv header java

扶醉桌前 提交于 2019-12-11 10:16:31

问题


I'm trying to write a code where a csv content is converted to a bean. This is how my code looks like

final String TEMPLATE_FILE="addresses.csv";

    CSVReader template = new CSVReader(new FileReader(TEMPLATE_FILE));
    String [] header = template.readNext();
    ColumnPositionMappingStrategy strat = new ColumnPositionMappingStrategy();
    strat.setType(PersonEx.class);
    strat.setColumnMapping(header);
    CsvToBean csv = new CsvToBean();
    List list = csv.parse(strat, template);

In here if a particular attribute of PersonEx.class is missing in the csvHeader that attribute is ascribed as null. Is there a way, I can ignore this and only create a bean of values present in the header?

来源:https://stackoverflow.com/questions/15596438/csv-to-bean-excluding-the-values-not-included-in-csv-header-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!