我有以下路线:
from("direct:abc")
// read the file
.split(body().tokenize("\n", 3, false)).streaming().stopOnException()
.unmarshal(new BindyCsvDataFormat(Foo.class))
.process(new FooListProcessor());问题是,如果我在文件中有4条记录,第一个group在处理器中作为List,第二个作为单个Foo对象。每次发生这种情况时,我都要用instanceof检查body并创建一个列表。
Foo类:
@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
发布于 2018-03-05 18:27:58
如果存在单个实例,则No bindy返回单个实例。这里有更多的列表。
我已经记录了一个改进的工单,所以你可以这样配置:https://issues.apache.org/jira/browse/CAMEL-12321
发布于 2018-03-05 18:41:14
只有一个小问题。因为它不像@Claus所说的那样被支持,而不是你在处理器代码中做实例检查,你也可以像这样做,让camel为你处理它。
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();https://stackoverflow.com/questions/49106881
复制相似问题