...
Code Block |
---|
from("activemq:My.Queue").
unmarshal().jacksonxml().
to("mqseries:Another.Queue");
|
Using Jackson XML in Spring DSL
When using Data Format in Spring DSL you need to declare the data formats first. This is done in the DataFormats XML tag.
Code Block |
---|
|
<dataFormats>
<!-- here we define a Xml data format with the id jack and that it should use the TestPojo as the class type when
doing unmarshal. The unmarshalTypeName is optional, if not provided Camel will use a Map as the type -->
<jacksonxml id="jack" unmarshalTypeName="org.apache.camel.component.jacksonxml.TestPojo"/>
</dataFormats>
|
And then you can refer to this id in the route:
Code Block |
---|
|
<route>
<from uri="direct:back"/>
<unmarshal ref="jack"/>
<to uri="mock:reverse"/>
</route>
|
Excluding POJO fields from marshalling
When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use JSON views to accomplish this. First create one or more marker classes.
Wiki Markup |
---|
{snippet:id=marker|lang=java|url=camel/trunk/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/Views.java} |
Use the marker classes with the @JsonView
annotation to include/exclude certain fields. The annotation also works on getters. Wiki Markup |
---|
{snippet:id=jsonview|lang=java|url=camel/trunk/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/TestPojoView.java} |
Finally use the Camel JacksonXMLDataFormat
to marshall the above POJO to XML. Wiki Markup |
---|
{snippet:id=format|lang=java|url=camel/trunk/components/camel-jacksonxml/src/test/java/org/apache/camel/component/jacksonxml/JacksonMarshalViewTest.java} |
Note that the weight field is missing in the resulting JSON: Code Block |
---|
{"age":30, "weight":70} |
Dependencies
To use Jackson XML in your camel routes you need to add the dependency on camel-jacksonxml which implements this data format.
...