I have created a MappingsBean class where all the columns of the CSV file are specified. Next I parse XML files and create a list of mappingbeans. Then I write that data int
Try something like below:
private static class CustomMappingStrategy extends ColumnPositionMappingStrategy {
String[] header;
public CustomMappingStrategy(String[] cols) {
header = cols;
}
@Override
public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException {
return header;
}
}
Then use it as follows:
String[] columns = new String[]{"Name", "Age", "Company", "Salary"};
CustomMappingStrategy mappingStrategy = new CustomMappingStrategy(columns);
Where columns are columns of your bean and Employee is your bean