Versions Compared

Key

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

...

Code Block
 <dataFormats>
      <json id="json" library="Jackson" unmarshalTypeName="com.foo.MyPojo" disableFeatures="FAIL_ON_UNKNOWN_PROPERTIES"/>
    </dataFormats>

You can disable multiple features by separating the values using comma. The values for the features must be the name of the enums from Jackson from the following enum classes

...

Code Block
JacksonDataFormat df = new JacksonDataFormat(MyPojo.class);
df.disableFeature(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
df.disableFeature(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);

 

 new JacksonDataFormat(MyPojo.class);
df.disableFeature(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
df.disableFeature(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);

Formatted JSON marshalling

Available as of Camel 2.16

Using the prettyPrint option one can output a well formatted JSON while marshalling:

Code Block
 <dataFormats>
      <json id=“json1” prettyPrint=“true”/>
      <json id=“json2” prettyPrint=“true” library=“Jackson"/>
      <json id=“json3” prettyPrint=“true” library="Gson"/>
 </dataFormats>

And in Java DSL:

Code Block
from(“direct:inPretty").marshal().json(true);
 
from("direct:inPretty").marshal().json(JsonLibrary.Jackson, true);
 
from("direct:inPretty").marshal().json(JsonLibrary.Gson, true);

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.

...

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