简体   繁体   English

将Apache Camel JSON数据格式从XML转换为Java DSL

[英]Convert Apache Camel JSON data format from XML to Java DSL

We're converting legacy Camel routes from XML to Java DSL, having trouble with JSON/Jackson data format we use for marshalling. 我们正在将传统的骆驼路线从XML转换为Java DSL,但无法使用用于编组的JSON / Jackson数据格式。 This is how we do it in XML: 这就是我们在XML中的处理方式:

<camelContext id="camelContext">
    <dataFormats>
        <json id="json"
            library="Jackson"
            allowJmsType="true"
            disableFeatures="WRITE_DATES_AS_TIMESTAMPS"/>
    </dataFormats>
</camel>

 <route id="myRoute">
    <from uri="seda:inqueue"/>
      <marshal>
          <json library="Jackson" />
      </marshal>
      <to  uri="seda:outqueue />
  </route>

...and this is the Java version (so far)... ...这是Java版本(到目前为止)...

@Bean(name = "json")
    public JacksonDataFormat jacksonDataFormat() {
        JacksonDataFormat format = new JacksonDataFormat();
        format.setAllowJmsType(true);
        format.disableFeature(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
        return format;
}

from("seda:inqueue")
    .marshal(json)
    .to("seda:outqueue");

Am I on the right path? 我在正确的道路上吗?

Also, what is the difference between these two methods? 另外,这两种方法有什么区别? My guess is the first one converts Json TEXT to byte stream, the second converts an object to Json TEXT; 我的猜测是,第一个将Json TEXT转换为字节流,第二个将对象转换为Json TEXT; is that accurate? 准确吗?

from("seda:inqueue")
    .marshal(json)
    .to("seda:outqueue");

from("seda:inqueue")
    .json(JsonLibrary.Jackson)
    .to("seda:outqueue");

I would suggest to use Camel XML Json component to achieve this rather than blindly migrating them. 我建议使用Camel XML Json组件来实现此目的,而不是盲目地迁移它们。 XML JSON component XML JSON组件

.marshal can used for generating any format based on configurations like BeanIO streams, CSV records and so on..json can be used for generating the JSON only. .marshal可用于基于BeanIO流,CSV记录等配置生成任何格式。.json仅可用于生成JSON。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM