csvapache-camelbindy

Empty @Link fields not in CSV, missing columns


I'm trying to generate a CSV file with fields from multiple entities. In my Camel route I have a BindyCsvDataFormat for my entity. However, if SubEntity is null then the SubEntity fields are not exported to the CSV file as "". So certain rows are missing columns. Null values in the MainEntity are exported as "". How do I configure Bindy to export SubEntity columns as "" when SubEntity is null?

The entities are linked together like so:

@Entity
@CsvRecord(separator=",", generateHeaderColumns=true)
public class MainEntity {

    @DataField(pos = 1, position = 1, columnName="firstColumn")
    private String column;

    @ManyToOne
    @Link
    private SubEntity subEntity;
    ...
}

@Entity
@Link
public class SubEntity {

    @DataField(pos = 2, position = 2, columnName="secondColumn")
    private String name;
    ...
}

Solution

  • I ended up not using @Link since it can't handle null objects. Instead I created a DTO like so:

    @CsvRecord(separator=",", generateHeaderColumns=true)
    public class EntityDTO {
    
        @DataField(pos = 1, position = 1, columnName="firstColumn")
        private String column;
    
        @DataField(pos = 2, position = 2, columnName="secondColumn")
        private String subEntityName;
    }