如何强制 Bindy 总是 return 列表?

How to force Bindy to always return List?

我有以下路线:

from("direct:abc")
        // read the file  
        .split(body().tokenize("\n", 3, false)).streaming().stopOnException()
        .unmarshal(new BindyCsvDataFormat(Foo.class))
        .process(new FooListProcessor());

问题是,如果我在文件中有 4 条记录,第一组作为 List 进入处理器,而第二组作为单个 Foo 对象进入处理器。 我必须用 instanceof 检查 body 并在每次发生这种情况时创建一个列表。

Foo class:

@CsvRecord(separator = ",")
public class Foo {
   @DataField(pos = 1)
   private String fooField;
   @DataField(pos = 2, trim = true)
   private String barField;
}

文件内容:

"lorem","ipsum"
"dolorem","sit"
"consectetur","adipiscing"
"eiusmod","incididunt"

有没有办法强制 Bindy 始终解组为 List

没有绑定 returns 如果有单个实例,则为单个实例。还有更多的列表。

我已经记录了改进的票证,因此您可以配置它:https://issues.apache.org/jira/browse/CAMEL-12321

只是一点点。由于它不受@Claus 所说的支持,因此您也可以在这样的路线中执行它,而不是您执行检查处理器代码的实例,让骆驼为您处理。

  from("file:///tmp/camel/input")
            // read the file
            .split(body().tokenize("\n", 3, false)).streaming().stopOnException()
            .unmarshal(new BindyCsvDataFormat(Foo.class))
            .choice()
            .when(body().isInstanceOf(List.class))
                .process(exchange -> { // Your logic here for list})
            .otherwise()
                .process(exchange -> {// Your logic here for individual items})
            .endChoice();