【问题标题】:Apache Camel - GSON formatterApache Camel - GSON 格式化程序
【发布时间】:2013-03-28 15:36:48
【问题描述】:

当 json 对象来自 Apache-Camel 上下文时,我想格式化我的 gson。在我的 application_context.xml 中相关字段是这样的:

 <camel:camelContext>
        <camel:dataFormats>
            <camel:json  id="gson" library="Gson" unmarshalTypeName="com.pzt.blz.fraud.domain.Payment"  />
        </camel:dataFormats>
        <camel:route>
            <camel:from uri="rabbitmq::blz.service.component.fraud?autodelete=false&amp;durable=true"/>
            <camel:unmarshal ref="gson"></camel:unmarshal>
               <camel:process ref="fraudProccessor"></camel:process>
            <camel:marshal ref="gson"></camel:marshal>
            <camel:inOnly uri="rabbitmq::blz.service.component.fraud-reply?autodelete=false&amp;durable=true"/>
        </camel:route>
    </camel:camelContext>

Camel:unmarshal 和 Camel:marshal 部分正在对对象执行 json,反之亦然。但是我想在此文件上添加一些属性,例如:

public Gson createGson(){
    return new GsonBuilder().
            setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).
            setPrettyPrinting().
            serializeNulls().
            create();

}

如何将FieldNamingPolicy 设置为 LOWER_CASE_WITH_UNDERSCORES 或 LOWER_CASE_WITH_DASHES 等...

有没有机会在骆驼上格式化这个?这些更改应该在我的 application_context.xml 文件中完成。

感谢所有回复...

【问题讨论】:

    标签: json spring apache gson apache-camel


    【解决方案1】:

    我认为我们没有在 XML DSL 中公开这些选项,因此您可以在 gson 数据格式上进行配置。我已经记录了一张票,以便在未来的 Camel 版本中实现这一点:https://issues.apache.org/jira/browse/CAMEL-6227

    【讨论】:

      猜你喜欢
      • 2018-03-19
      • 1970-01-01
      • 2018-03-16
      • 1970-01-01
      • 2016-08-24
      • 1970-01-01
      • 2019-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多