apache-camelbindy

Bindy - Apache Camel. Can a position (column) be ignored while unmarshaling CSV?


I am using camel-bindy to unmarshall a CSV to Java Object. Is it possible to ignore a particular column? Consider following example, I don't want to map column 3 (Address). Please let me know if there is a way to do so. In reality I have more than 10 columns in my CSV that I want to ignore.

Example :- CSV File:

 Header   : Name,Mobile,Address
 Data Row : Rabbit,007,Rabbit Hole

Bindy mapping in Java class:

@CsvRecord(separator = "," , skipFirstLine = true) 
public class Contacts {

@DataField(pos = 1, trim=true)
private String name;

@DataField(pos = 2, required = true, trim=true) 
private Long Mobile;

Thanks for your time!


Solution

  • You cannot skip a column. Bindy iterates through every token and checks if there is an associated data field, see BindyCsvFactory:

    // Get DataField from model
    DataField dataField = dataFields.get(pos);
    ObjectHelper.notNull(dataField, "No position " + pos + " defined for the field: " + data + ", line: " + line);
    

    The only solution is to define a class attribute that is just ignored:

    @DataField(pos = 1)
    public String ingoreMe;