Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
xml:titleUsing gson from Camel routes
   <camelContext xmlns="http://camel.apache.org/schema/spring">

        <route>
            <from uri="direct:inPojo"/>
            <marshal ref="gson"/>
        </route>

        <route>
            <from uri="direct:backPojo"/>
            <unmarshal ref="gson"/>
        </route>

    </camelContext>

Include/Exclude fields using the jsonView attribute with JacksonDataFormat

Available as of Camel 2.12

As an example of using this attribute you can instead of:

Code Block
java
java

JacksonDataFormat ageViewFormat = new JacksonDataFormat(TestPojoView.class, Views.Age.class);
from("direct:inPojoAgeView").
  marshal(ageViewFormat);

Directly specify the JSON view inside the Java DSL as:

Code Block
java
java

from("direct:inPojoAgeView").
  marshal().json(TestPojoView.class, Views.Age.class);

And the same in XML DSL:

Code Block
java
java

<from uri="direct:inPojoAgeView"/>
  <marshal>
    <json library="Jackson" unmarshalTypeName="org.apache.camel.component.jackson.TestPojoView" jsonView="org.apache.camel.component.jackson.Views$Age"/>
  </marshal>

Dependencies for XStream

To use JSON in your camel routes you need to add the a dependency on camel-xstream which implements this data format.

...