77.4. 将 CSV 消息写入 Java 列表中
unmarshalling 将 CSV 条形转换为带有 CSV 文件行的 Java 列表(包含带有所有字段值的另一个列表)。
例如:我们有一个 CSV 文件,其名称为个人、IQ 及其当前活动。
Jack Dalton, 115, mad at Averell
Joe Dalton, 105, calming Joe
William Dalton, 105, keeping Joe from killing Averell
Averell Dalton, 80, playing with Rantanplan
Lucky Luke, 120, capturing the Daltons
现在,我们可以使用 CSV 组件 unmarshal 这个文件:
from("file:src/test/resources/?fileName=daltons.csv&noop=true")
.unmarshal().csv()
.to("mock:daltons");
生成的消息将包含一个 List<List<String>>,如…
List<List<String>> data = (List<List<String>>) exchange.getIn().getBody();
for (List<String> line : data) {
LOG.debug(String.format("%s has an IQ of %s and is currently %s", line.get(0), line.get(1), line.get(2)));
}