2

I found several examples of Apache Camel Bindy unmarshalling CSV records into POJOs using field position:

@CsvRecord(separator = ",")
public class Person {

    @DataField(pos = 1)
    private String name;
    @DataField(pos = 2)
    private String address;

I have 50+ different CSV files that I want to unmarshall into the same POJO. Each file has a header. The header names remain constant between the files, but the field position varies. For example,

File1.csv
--------------------------- 
name,homeAddress,someOtherFields
bob,123 Any Street,data
 
File2.csv 
---------------------------
homeAddress,name,someOtherFields
321 XYZ Street,jill,data
 
File3.csv 
---------------------------
name,someOtherFields,homeAddress 
sue,data,123 Any Street
 
etc.

I was hoping something like this would work:

@CsvRecord(separator = ",")
public class Person {

    @DataField(columnName = "name")
    private String name;
    @DataField(columnName = "homeAddress")
    private String address;

But columnName seems to be used for ouptut only. Also, pos is required.

James
  • 2,876
  • 18
  • 72
  • 116

0 Answers0