0

I would like to format my gson when the json object came via Apache-Camel context. In my application_context.xml related field is like this:

 <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 and Camel:marshal parts are doing the json to object and vice versa thing.However I would like to add some properties on this file like:

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

}

How can I setFieldNamingPolicy to LOWER_CASE_WITH_UNDERSCORES or LOWER_CASE_WITH_DASHES etc...

Is there any chance to format this on Camel? and these changes should be done at my application_context.xml file.

Appreciate for all replies...

4

1 回答 1

0

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

于 2013-03-31T06:55:01.857 回答