2013-11-28 36 views
0

如何使用輸出文件的Java DSL更改csv分隔符?使用Java DSL更改CSV輸出分隔符

from("timer://foo?fixedRate=true&delay=0&period=2000"). 
to("http://graph.facebook.com/nike").unmarshal().json(JsonLibrary.Gson,Map.class) 
.marshal().csv().to("file:target/output"); 

回答

1

你可以試試這個:

CsvDataFormat csv = new CsvDataFormat(); 
CSVConfig config = new CSVConfig(); 
config.setDelimiter('|'); // your delimiter here 
csv.setConfig(config); 

from("timer://foo?fixedRate=true&delay=0&period=2000"). 
to("http://graph.facebook.com/nike").unmarshal().json(JsonLibrary.Gson,Map.class) 
.marshal(csv).convertBodyTo(String.class).to("file:target/output"); 

不知道convertBodyTo(String.class)是必要的

+0

你使用哪個版本?我使用2.12並沒有CSVConfig。你可以調用:csv.setDelimiter('|'); – aphex

+0

我使用的是版本2.10 –