I am using OpenCSV 4.6 to read and write csv files. I have a java bean like
public class CMMProjectInfo implements Serializable {
private static final long serialVersionUID = 1L;
@CsvBindByName(column = "ProjectName",required = true)
private String projectName;
@CsvBindByName(column = "ProjectCode",required = true)
private String projectCode;
@CsvBindByName(column = "Visibility",required = true)
private String visibility;
}
If user uploads valid csv file like below
ProjectCode;ProjectName;Visibility
T1;Test, 1;1
T2;Test2;0
TST;Test3;1
we are able to map the headers to object by using HeaderColumnNameMappingStrategy. If user edits the csv file using excel editor then file is changing like below(it's appending additional characs(, and "))
ProjectCode;ProjectName;Visibility,
T1;Test,1;1
T2;Test2;0,
TST;Test3;1,
Now if user uploads the file which was edited by excel file then failed to map the headers and getting error Error capturing CSV header! because when we try to map headers it will split based on delimiter(;) then values will be 1. ProjectCode 2. ProjectName and 3.Visibility, last header value has additional characters that's why it's failing to map the header name from Visibility to Visibility,
Note: Here problem with comma(,) in input file. I cannot restrict the user to upload file which has comma in values.
Is there any way to solve this issue while mapping the headers?