Versions Compared

Key

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

...

Code Block
xml:titleConfiguring GsonDataFormat in Spring XML file
languagexml
titleConfiguring GsonDataFromat in Spring XML file
    <!-- define the gson data format, where we configure the data format using the properties -->
    <bean id="gson" class="org.apache.camel.component.gson.GsonDataFormat">
        <!-- we want to unmarshal to person pojo -->
        <property name="unmarshalType" value="org.apache.camel.component.gson.PersonPojo"/>
        <!-- we want to map fields to use lower case and underscores -->
        <property name="fieldNamingPolicy" value="LOWER_CASE_WITH_UNDERSCORES"/>
    </bean>

...

Code Block
xml:titleUsing gson from Camel routes
languagexml
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>

...

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

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

Directly specify your JSON view inside the Java DSL as:

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

And the same in XML DSL:

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

...

If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).

Code Block
xml
languagexml
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-xstream</artifactId>
  <version>2.9.2</version>
</dependency>

...

If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).

Code Block
xml
languagexml
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-jackson</artifactId>
  <version>2.9.2</version>
</dependency>

...

If you use maven you could just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).

Code Block
xml
languagexml
<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-gson</artifactId>
  <version>2.10.0</version>
</dependency>