Entaxy Docs

JSON XStream

Since Camel 2.0

XStream is a Data Format which uses the XStream library to marshal and unmarshal Java objects to and from JSon. However XStream was created primary for working with XML and therefore using JSon with XStream is not as popular as for example Jackson is for JSon.

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

Maven users will need to add the following dependency to their pom.xml for this component:

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-xstream</artifactId>
  <version>x.x.x</version>
  <!-- use the same version as your Camel core version -->
</dependency>

Options

The JSON XStream dataformat supports 3 options, which are listed below.

Name Default Java Type Description

prettyPrint

false

Boolean

To enable pretty printing output nicely formatted. Is by default false.

dropRootNode

false

Boolean

Whether XStream will drop the root node in the generated JSon. You may want to enable this when using POJOs; as then the written object will include the class name as root node, which is often not intended to be written in the JSON output.

contentTypeHeader

false

Boolean

Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc.

Using the Java DSL

// lets turn Object messages into XML then send to MQSeries
from("activemq:My.Queue").
  marshal().json(JsonLibrary.XStream).
  to("mqseries:Another.Queue");