骆驼如何以流模式处理json? [英] camel how to process json with streaming mode?
问题描述
为了在流模式下读取json并解组,Camel OOB中有哪些可用选项?如果不是开箱即用,如何实现?
In order to read json and unmarshal in streaming mode what options are available in Camel OOB ? If not out of box how can this be implemented ?
我发现camel-xstream可能会有所帮助.流模式是此模式的默认设置还是我们需要做一些其他事情以使其在流模式下读取?
I found camel-xstream which might help. Is streaming mode a default of this or do we need to do something else to make it read in streaming mode ?
还有杰克逊流式API.骆驼可以通行吗?
There is also jackson streaming api. Is that accessible with camel ?
一些例子会有所帮助. 谢谢
Some examples would help. Thanks
推荐答案
您可以使用 JSON数据格式,以将Java对象与JSON封送和封送.
You can use JSON data format, to to marshal and unmarshal Java objects to and from JSON.
类似于.marshal().json(JsonLibrary.Jackson)
的东西,它使用Jackson图书馆,您也可以使用其他东西.
Some thing like .marshal().json(JsonLibrary.Jackson)
which uses Jackson Library, You can use others as well.
以下是一个示例配置,用于流csv文件内容并转换为JSON,然后调用MyBean类的publish方法.
Following is a sample configuration to stream csv file content and convert to JSON and then call publish method of MyBean class.
CsvDataFormat csv = new CsvDataFormat();
csv.setDelimiter(",");
csv.setQuoteDisabled(true);
csv.setUseMaps(true);
csv.setLazyLoad(true);
csv.setHeader(Arrays.asList("head1","head2","head3","message"));
from("file:///test/?fileName=test.csv&noop=true").split(body().tokenize("\n")).streaming().unmarshal(csv).marshal().json(JsonLibrary.Jackson).bean(MyBean.class,"publish").log("done.").end();
这篇关于骆驼如何以流模式处理json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!