Camel Exchange body 记录大小

Camel Exchange body record size

场景:

问题:

尝试过:

代码:

    public void process(Exchange exchange) throws Exception {
    List<Cars> output = new ArrayList<Cars>();
    **List<Wehicle> rows = (List<Wehicle>) exchange.getIn().getBody(); <-- Fails**

    for (Wehicle row: rows) {
        output.add(new Cars(row));
    }

    exchange.getIn().setBody(output);
    exchange.getIn().setHeader("CamelOverruleFileName", "CarEntries.csv");
}

汽车

...
@CsvRecord(separator = ",", skipFirstLine = true, crlf = "UNIX")
public class Wehicle {
    @DataField(pos = 1)
    public String CouponCode;

    @DataField(pos = 2)
    public String Price;
}
...

汽车

@CsvRecord(separator = ",", crlf = "UNIX", generateHeaderColumns = true)
public class Cars {
    @DataField(pos = 1, columnName = "CouponCode")
    private String CouponCode;

    @DataField(pos = 2, columnName = "Price")
    private String Price;
    
    public Cars(Wehicle origin) {
        this.CouponCode = Utilities.addQuotesToString(origin.CouponCode);
        this.Price = origin.Price;
    }
}

输入:

"CouponCode","Price"
"ASD/785", 1900000
"BWM/758", 2000000

问题:

好久没用java,加之camel新手安静

重新检查官方文档后,似乎以下更改正在解决问题。

代码:

    public void process(Exchange exchange) throws Exception {
    List<Cars> output = new ArrayList<Cars>();
    List records = exchange.getIn().getBody(List.class);
    (List<Wehicle>) rows = (List<Wehicle>) records;

    for (Wehicle row: rows) {
        output.add(new Cars(row));
    }

    exchange.getIn().setBody(output);
    exchange.getIn().setHeader("CamelOverruleFileName", "CarEntries.csv");
   }