74.3. CSV メッセージの Java リストへのアンマーシャリング
アンマーシャリングは、CSV ファイル行が含まれる CSV コンテナーが Java List に変換されます(フィールド値すべてが含まれる別の List も含まれます)。
例: CSV ファイルに persons の名前、その 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
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 コンポーネントを使用して、このファイルをアンマーシャリングできるようになりました。
from("file:src/test/resources/?fileName=daltons.csv&noop=true") .unmarshal().csv() .to("mock:daltons");
from("file:src/test/resources/?fileName=daltons.csv&noop=true")
.unmarshal().csv()
.to("mock:daltons");
作成されるメッセージには、List< List<String>>
like…
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))); }
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)));
}