Versions Compared

Key

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

...

Code Block
    <dataFormats>
      <jacksonxml id="jsonjack" useList="true"/>
    </dataFormats>

And you can specify the pojo type also

Code Block
    <dataFormats>
      <json<jacksonxml id="json" library="Jacksonjack" useList="true" unmarshalTypeName="com.foo.MyPojo"/>
    </dataFormats>

...

You can use custom Jackson modules by specifying the class names of those using the moduleClassNames option as shown below.

Code Block
    <dataFormats>
      <json<jacksonxml id="json" library="Jacksonjack" useList="true" unmarshalTypeName="com.foo.MyPojo" moduleClassNames="com.foo.MyModule,com.foo.MyOtherModule"/>
    </dataFormats>

...

Code Block
    <bean id="myJacksonModule" class="com.foo.MyModule">
      ... // configure the module as you want
    </bean>
 
    <dataFormats>
      <json<jacksonxml id="json" library="Jackson" useList="true" unmarshalTypeName="com.foo.MyPojo" moduleRefs="myJacksonModule"/>
    </dataFormats>

...

Enabling or disable features using Jackson

Available as of Camel 2.15

Jackson has a number of features you can enable or disable, which its ObjectMapper uses. For example to disable failing on unknown properties when marshalling, you can configure this using the disableFeatures:

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

...

Converting Maps to POJO using Jackson

Available since Camel 2.16. Jackson ObjectMapper can be used to convert maps to POJO objects. Jackson component comes with the data converter that can be used to convert java.util.Map instance to non-String, non-primitive and non-Number objects.

...

If there is a single ObjectMapper instance available in the Camel registry, it will used by the converter to perform the conversion. Otherwise the default mapper will be used.  

Formatted

...

XML marshalling (pretty-printing)

Available as of Camel 2.16

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

Code Block
 <dataFormats>
      <json<jacksonxml id="xstreamjack" prettyPrint="true"/>
      <json id="jackson" prettyPrint="true" library="Jackson"/>
      <json id="gson" 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, jacksonxml(true);

Please note that as of Camel 2.16 there’re there are 5 different overloaded jsonjacksonxml() DSL methods which support the prettyPrint option in combination with other settings for JsonLibraryunmarshalTypejsonView etc. 

...