Versions Compared

Key

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

...

Code Block
    <dataFormats>
      <json id="json" library="Jackson" allowJmsType="true"/>
    </dataFormats>

Unmarshalling from json to List<Map> or List<pojo>

Available as of Camel 2.14

If you are using Jackson to unmarshal json to a list of map/pojo, you can now specify this by setting useList="true" or use the org.apache.camel.component.jackson.ListJacksonDataFormat. For example with Java you can do as shown below:

Code Block
JacksonDataFormat format = new ListJacksonDataFormat();
// or
JacksonDataFormat format = new JacksonDataFormat();
format.useList();
// and you can specify the pojo class type also
format.setUnmarshalType(MyPojo.class);

And if you use XML DSL then you configure to use list using useList attribute as shown below:

Code Block
    <dataFormats>
      <json id="json" library="Jackson" useList="true"/>
    </dataFormats>

And you can specify the pojo type also

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

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.

...