骆驼如何使用流模式处理json? [英] camel how to process json with streaming mode?

查看:30
本文介绍了骆驼如何使用流模式处理json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了在流模式下读取 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 ?

还有jackson Streaming api.可以用骆驼访问吗?

There is also jackson streaming api. Is that accessible with camel ?

一些例子会有所帮助.谢谢

Some examples would help. Thanks

推荐答案

您可以使用 JSON 数据 格式,用于在 JSON 中编组和解组 Java 对象.

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 类的发布方法.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆