简体   繁体   中英

Apache Camel - GSON formatter

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...

I don't think we have exposes those options in the XML DSL so you can configure this on the gson data format. I have logged a ticket to implement this in a future Camel release: https://issues.apache.org/jira/browse/CAMEL-6227

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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