OpenCsv to write csv file with variable number of columns in order

I have a csv file with varible number of columns like

STARTDATE,ENDDATE,NAME,C1,C2,C3,C4 2016-10-12,2017-10-12,Sasi,1,7,8,7 2015-10-12,2019-10-12,Soman,5,7,8,8 

Here STARTDATE,ENDDATE,NAME will be available for all csv, but other columns may vary.

@Data class DataBean {   @CsvBindByName(column="STARTDATE")   @CsvDate('yyyy-mm-dd')   private LocalDate startDate;    @CsvBindByName(column="ENDDATE")   @CsvDate('yyyy-mm-dd')   private LocalDate endDate;    @CsvBindByName(column="NAME")   private String name;    @CsvBindAndJoinByName(column=".*", elementType=String.class)   private MultiMap<String, String> otherFields; } 

I can parse csv file using the above bean and CsvToBean to a list of DataBean
While writing the list back to the file, the column order is in alphabetic order

Is there a way to create a csv file from DataBean list

  1. Column names must be StartDate,EndDate,Name,.....other fields
  2. Column order is first StartDate, then EndDate, then Name then other fields
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.