Modified: websites/production/camel/content/json.html
==============================================================================
--- websites/production/camel/content/json.html (original)
+++ websites/production/camel/content/json.html Fri Aug 25 08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: JSON
@@ -86,100 +75,39 @@
<tbody>
<tr>
<td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="JSON-JSON">JSON</h2><p>JSON is a
<a shape="rect" href="data-format.html">Data Format</a> to marshal and
unmarshal Java objects to and from <a shape="rect" class="external-link"
href="http://www.json.org/" rel="nofollow">JSON</a>.</p><p>For JSON to object
marshalling, Camel provides integration with three popular JSON
libraries:</p><ul class="alternate"><li>The <a shape="rect"
class="external-link" href="http://xstream.codehaus.org/"
rel="nofollow">XStream library</a> and <a shape="rect" class="external-link"
href="http://jettison.codehaus.org/" rel="nofollow">Jettsion </a></li><li>The
<a shape="rect" class="external-link"
href="https://github.com/FasterXML/jackson" rel="nofollow">Jackson
library</a></li><li><strong>Camel 2.10:</strong> The <a shape="rect"
class="external-link" href="http://code.google.com/p/google-gson/"
rel="nofollow">GSon library</a></li></ul><p>Every library requires adding the
special camel component (see "Dependency
..." paragraphs further down). By default Camel uses the XStream
library.</p><div class="confluence-information-macro
confluence-information-macro-tip"><p class="title">Direct, bi-directional JSON
<=> XML conversions</p><span class="aui-icon aui-icon-small
aui-iconfont-approve confluence-information-macro-icon"></span><div
class="confluence-information-macro-body"><p>As of Camel 2.10, Camel supports
direct, bi-directional JSON <=> XML conversions via the <a shape="rect"
href="xmljson.html">camel-xmljson</a> data format, which is documented
separately.</p></div></div><h3
id="JSON-UsingJSONDataFormatWiththeXStreamLibrary">Using JSON Data Format With
the <code>XStream</code> Library</h3><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// Let's turn Object messages into JSON
then send to MQSeries
-from("activemq:My.Queue")
+<div class="wiki-content maincontent"><h2 id="JSON-JSON">JSON</h2><p>JSON is a
<a shape="rect" href="data-format.html">Data Format</a> to marshal and
unmarshal Java objects to and from <a shape="rect" class="external-link"
href="http://www.json.org/" rel="nofollow">JSON</a>.</p><p>For JSON to object
marshalling, Camel provides integration with three popular JSON
libraries:</p><ul class="alternate"><li>The <a shape="rect"
class="external-link" href="http://xstream.codehaus.org/"
rel="nofollow">XStream library</a> and <a shape="rect" class="external-link"
href="http://jettison.codehaus.org/" rel="nofollow">Jettsion </a></li><li>The
<a shape="rect" class="external-link"
href="https://github.com/FasterXML/jackson" rel="nofollow">Jackson
library</a></li><li><strong>Camel 2.10:</strong> The <a shape="rect"
class="external-link" href="http://code.google.com/p/google-gson/"
rel="nofollow">GSon library</a></li></ul><p>Every library requires adding the
special camel component (see "Dependency
..." paragraphs further down). By default Camel uses the XStream
library.</p><parameter ac:name="title">Direct, bi-directional JSON <=>
XML conversions</parameter><rich-text-body><p>As of Camel 2.10, Camel supports
direct, bi-directional JSON <=> XML conversions via the <a shape="rect"
href="xmljson.html">camel-xmljson</a> data format, which is documented
separately.</p></rich-text-body><h3
id="JSON-UsingJSONDataFormatWiththeXStreamLibrary">Using JSON Data Format With
the <code>XStream</code> Library</h3><parameter
ac:name="language">java</parameter><plain-text-body>// Let's turn Object
messages into JSON then send to MQSeries
+from("activemq:My.Queue")
.marshal().json()
- .to("mqseries:Another.Queue");
-]]></script>
-</div></div><h3 id="JSON-UsingJSONDataFormatWiththeJacksonLibrary">Using JSON
Data Format With the <code>Jackson</code> Library</h3><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// Let's turn Object messages into JSON
then send to MQSeries
-from("activemq:My.Queue")
+ .to("mqseries:Another.Queue");
+</plain-text-body><h3 id="JSON-UsingJSONDataFormatWiththeJacksonLibrary">Using
JSON Data Format With the <code>Jackson</code> Library</h3><parameter
ac:name="language">java</parameter><plain-text-body>// Let's turn Object
messages into JSON then send to MQSeries
+from("activemq:My.Queue")
.marshal().json(JsonLibrary.Jackson)
- .to("mqseries:Another.Queue");
-]]></script>
-</div></div><h3 id="JSON-UsingJSONDataFormatWiththeGSONLibrary">Using JSON
Data Format With the GSON Library</h3><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// Let's turn Object messages into JSON
then send to MQSeries
-from("activemq:My.Queue")
+ .to("mqseries:Another.Queue");
+</plain-text-body><h3 id="JSON-UsingJSONDataFormatWiththeGSONLibrary">Using
JSON Data Format With the GSON Library</h3><parameter
ac:name="language">java</parameter><plain-text-body>// Let's turn Object
messages into JSON then send to MQSeries
+from("activemq:My.Queue")
.marshal().json(JsonLibrary.Gson)
- .to("mqseries:Another.Queue");
-]]></script>
-</div></div><h4 id="JSON-UsingJSONinSpringDSL">Using JSON in Spring
DSL</h4><p>When using <a shape="rect" href="data-format.html">Data Format</a>
in Spring DSL you need to declare the data formats first. This is done in the
<strong><code>DataFormats</code></strong> XML tag.</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dataFormats>
+ .to("mqseries:Another.Queue");
+</plain-text-body><h4 id="JSON-UsingJSONinSpringDSL">Using JSON in Spring
DSL</h4><p>When using <a shape="rect" href="data-format.html">Data Format</a>
in Spring DSL you need to declare the data formats first. This is done in the
<strong><code>DataFormats</code></strong> XML tag.</p><parameter
ac:name="language">xml</parameter><plain-text-body><dataFormats>
<!--
Here we define a Json 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.
-->
- <json id="jack" library="Jackson"
unmarshalTypeName="org.apache.camel.component.jackson.TestPojo"/>
+ <json id="jack" library="Jackson"
unmarshalTypeName="org.apache.camel.component.jackson.TestPojo"/>
</dataFormats>
-]]></script>
-</div></div><p>And then you can refer to this id in the route:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<route>
- <from uri="direct:back"/>
- <unmarshal ref="jack"/>
- <to uri="mock:reverse"/>
+</plain-text-body><p>And then you can refer to this id in the
route:</p><parameter
ac:name="language">xml</parameter><plain-text-body><route>
+ <from uri="direct:back"/>
+ <unmarshal ref="jack"/>
+ <to uri="mock:reverse"/>
</route>
-]]></script>
-</div></div><h3 id="JSON-ExcludingPOJOFieldsFromMarshalling">Excluding POJO
Fields From Marshalling</h3><p><strong>As of Camel 2.10</strong><br
clear="none"> When marshaling a POJO to JSON you might want to exclude certain
fields from the JSON output. With Jackson you can use <a shape="rect"
class="external-link" href="http://wiki.fasterxml.com/JacksonJsonViews"
rel="nofollow">JSON views</a> to accomplish this.</p><p>First create one or
more marker classes:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-public class Views {
-
- static class Age { }
- static class Weight { }
-}
-]]></script>
-</div></div>Second, use the marker classes with the
<strong><code>@JsonView</code></strong> annotation to include/exclude certain
fields. The annotation also works on getters:<div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-@JsonView(Views.Age.class)
-private int age = 30;
-
-private int height = 190;
-
-@JsonView(Views.Weight.class)
-private int weight = 70;
-]]></script>
-</div></div>Finally, use the Camel
<strong><code>JacksonDataFormat</code></strong> to marshal the above POJO to
JSON.<div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:inPojoAgeView").marshal().json(TestPojoView.class,
Views.Age.class);
-]]></script>
-</div></div><strong>Note</strong>: the height field is missing in the
resulting JSON.<div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[{"age":30, "weight":70}
-]]></script>
-</div></div><p>The GSON library supports a similar feature through the notion
of <a shape="rect" class="external-link"
href="http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/ExclusionStrategy.html"
rel="nofollow">ExclusionStrategies</a>:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-/**
- * Strategy to exclude {@link ExcludeAge} annotated fields
- */
-protected static class AgeExclusionStrategy implements ExclusionStrategy {
-
- @Override
- public boolean shouldSkipField(FieldAttributes f) {
- return f.getAnnotation(ExcludeAge.class) != null;
- }
-
- @Override
- public boolean shouldSkipClass(Class<?> clazz) {
- return false;
- }
-}
-]]></script>
-</div></div>The <strong><code>GsonDataFormat</code></strong> accepts an
<strong><code>ExclusionStrategy</code></strong> in its constructor:<div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-GsonDataFormat ageExclusionFormat = new
GsonDataFormat(TestPojoExclusion.class);
-ageExclusionFormat.setExclusionStrategies(Arrays.<ExclusionStrategy>asList(new
AgeExclusionStrategy()));
-from("direct:inPojoExcludeAge").marshal(ageExclusionFormat);
-]]></script>
-</div></div>The line above will exclude fields annotated with
<strong><code>@ExcludeAge</code></strong> when marshaling to JSON.<h3
id="JSON-ConfiguringFieldNamingPolicy">Configuring Field Naming
Policy</h3><p><strong>Available as of Camel 2.11</strong></p><p>The GSON
library supports specifying policies and strategies for mapping from JSON to
POJO fields. A common naming convention is to map JSON fields using lower case
with underscores.</p><p>We may have this JSON string</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[{
- "id" : 123,
- "first_name" : "Donald"
- "last_name" : "Duck"
+</plain-text-body><h3 id="JSON-ExcludingPOJOFieldsFromMarshalling">Excluding
POJO Fields From Marshalling</h3><p><strong>As of Camel 2.10</strong><br
clear="none"> When marshaling a POJO to JSON you might want to exclude certain
fields from the JSON output. With Jackson you can use <a shape="rect"
class="external-link" href="http://wiki.fasterxml.com/JacksonJsonViews"
rel="nofollow">JSON views</a> to accomplish this.</p><p>First create one or
more marker
classes:<plain-text-body>{snippet:id=marker|lang=java|url=camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/Views.java}</plain-text-body>Second,
use the marker classes with the <strong><code>@JsonView</code></strong>
annotation to include/exclude certain fields. The annotation also works on
getters:<plain-text-body>{snippet:id=jsonview|lang=java|url=camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/TestPojoView.java}</plain-text-body>Finally,
use the Camel <stro
ng><code>JacksonDataFormat</code></strong> to marshal the above POJO to
JSON.<plain-text-body>{snippet:id=format|lang=java|url=camel/trunk/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalViewTest.java}</plain-text-body><strong>Note</strong>:
the height field is missing in the resulting
JSON.</p><plain-text-body>{"age":30, "weight":70}
+</plain-text-body><p>The GSON library supports a similar feature through the
notion of <a shape="rect" class="external-link"
href="http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/ExclusionStrategy.html"
rel="nofollow">ExclusionStrategies</a>:<plain-text-body>{snippet:id=strategy|lang=java|url=camel/trunk/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java}</plain-text-body>The
<strong><code>GsonDataFormat</code></strong> accepts an
<strong><code>ExclusionStrategy</code></strong> in its
constructor:<plain-text-body>{snippet:id=format|lang=java|url=camel/trunk/components/camel-gson/src/test/java/org/apache/camel/component/gson/GsonMarshalExclusionTest.java}</plain-text-body>The
line above will exclude fields annotated with
<strong><code>@ExcludeAge</code></strong> when marshaling to JSON.</p><h3
id="JSON-ConfiguringFieldNamingPolicy">Configuring Field Naming
Policy</h3><p><strong>Available as of Camel 2.11</s
trong></p><p>The GSON library supports specifying policies and strategies for
mapping from JSON to POJO fields. A common naming convention is to map JSON
fields using lower case with underscores.</p><p>We may have this JSON
string</p><plain-text-body>{
+ "id" : 123,
+ "first_name" : "Donald"
+ "last_name" : "Duck"
}
-]]></script>
-</div></div><p>Which we want to map to a POJO that has getter/setters
as:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width:
1px;"><b>PersonPojo.java</b></div><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[public class PersonPojo {
+</plain-text-body><p>Which we want to map to a POJO that has getter/setters
as:</p><parameter ac:name="language">java</parameter><parameter
ac:name="java:title">PersonPojo.java</parameter><parameter
ac:name="title">PersonPojo.java</parameter><plain-text-body>public class
PersonPojo {
private int id;
private String firstName;
@@ -209,153 +137,102 @@ from("direct:inPojoExcludeAge"
this.lastName = lastName;
}
}
-]]></script>
-</div></div><p>Then we can configure the
<strong><code>org.apache.camel.component.gson.GsonDataFormat</code></strong> in
a Spring XML files as shown below. Notice we use
<strong><code>fieldNamingPolicy</code></strong> property to set the field
mapping. This property is an enum from GSon
<strong><code>com.google.gson.FieldNamingPolicy</code></strong> which has a
number of predefined mappings.</p><p>If you need full control you can use the
property <strong><code>FieldNamingStrategy</code></strong> and implement a
custom <strong><code>com.google.gson.FieldNamingStrategy</code></strong> where
you can control the mapping.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeHeader panelHeader pdl"
style="border-bottom-width: 1px;"><b>Configuring GsonDataFromat in Spring XML
file</b></div><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<!-- define the gson data format, where we
configure the data format using the properties -->
-<bean id="gson"
class="org.apache.camel.component.gson.GsonDataFormat">
+</plain-text-body><p>Then we can configure the
<strong><code>org.apache.camel.component.gson.GsonDataFormat</code></strong> in
a Spring XML files as shown below. Notice we use
<strong><code>fieldNamingPolicy</code></strong> property to set the field
mapping. This property is an enum from GSon
<strong><code>com.google.gson.FieldNamingPolicy</code></strong> which has a
number of predefined mappings.</p><p>If you need full control you can use the
property <strong><code>FieldNamingStrategy</code></strong> and implement a
custom <strong><code>com.google.gson.FieldNamingStrategy</code></strong> where
you can control the mapping.</p><parameter ac:name="xml:title">Configuring
GsonDataFormat in Spring XML file</parameter><parameter
ac:name="language">xml</parameter><parameter ac:name="title">Configuring
GsonDataFromat in Spring XML file</parameter><plain-text-body><!-- define
the gson data format, where we configure the data format using the properties
-->
+<bean id="gson" class="org.apache.camel.component.gson.GsonDataFormat">
<!-- we want to unmarshal to person pojo -->
- <property name="unmarshalType"
value="org.apache.camel.component.gson.PersonPojo"/>
+ <property name="unmarshalType"
value="org.apache.camel.component.gson.PersonPojo"/>
<!-- we want to map fields to use lower case and underscores -->
- <property name="fieldNamingPolicy"
value="LOWER_CASE_WITH_UNDERSCORES"/>
+ <property name="fieldNamingPolicy"
value="LOWER_CASE_WITH_UNDERSCORES"/>
</bean>
-]]></script>
-</div></div><p>And use it in Camel routes by referring to its bean id as
shown:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeHeader panelHeader pdl" style="border-bottom-width: 1px;"><b>Using
gson from Camel Routes</b></div><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<camelContext
xmlns="http://camel.apache.org/schema/spring">
+</plain-text-body><p>And use it in Camel routes by referring to its bean id as
shown:</p><parameter ac:name="xml:title">Using gson from Camel
routes</parameter><parameter ac:name="language">xml</parameter><parameter
ac:name="title">Using gson from Camel
Routes</parameter><plain-text-body><camelContext
xmlns="http://camel.apache.org/schema/spring">
<route>
- <from uri="direct:inPojo"/>
- <marshal ref="gson"/>
+ <from uri="direct:inPojo"/>
+ <marshal ref="gson"/>
</route>
<route>
- <from uri="direct:backPojo"/>
- <unmarshal ref="gson"/>
+ <from uri="direct:backPojo"/>
+ <unmarshal ref="gson"/>
</route>
</camelContext>
-]]></script>
-</div></div><h3
id="JSON-Include/ExcludeFieldsUsingthejsonViewAttributeWithJacksonDataFormat">Include/Exclude
Fields Using the <strong><code>jsonView</code></strong> Attribute With
<code>JacksonDataFormat</code></h3><p><strong>Available as of Camel
2.12</strong></p><p>As an example of using this attribute you can instead
of:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[JacksonDataFormat ageViewFormat = new
JacksonDataFormat(TestPojoView.class, Views.Age.class);
+</plain-text-body><h3
id="JSON-Include/ExcludeFieldsUsingthejsonViewAttributeWithJacksonDataFormat">Include/Exclude
Fields Using the <strong><code>jsonView</code></strong> Attribute With
<code>JacksonDataFormat</code></h3><p><strong>Available as of Camel
2.12</strong></p><p>As an example of using this attribute you can instead
of:</p><parameter
ac:name="language">java</parameter><plain-text-body>JacksonDataFormat
ageViewFormat = new JacksonDataFormat(TestPojoView.class, Views.Age.class);
-from("direct:inPojoAgeView")
+from("direct:inPojoAgeView")
.marshal(ageViewFormat);
-]]></script>
-</div></div><p>Directly specify your <a shape="rect" class="external-link"
href="http://wiki.fasterxml.com/JacksonJsonViews" rel="nofollow">JSON view</a>
inside the Java DSL as:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:inPojoAgeView")
+</plain-text-body><p>Directly specify your <a shape="rect"
class="external-link" href="http://wiki.fasterxml.com/JacksonJsonViews"
rel="nofollow">JSON view</a> inside the Java DSL as:</p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:inPojoAgeView")
.marshal().json(TestPojoView.class, Views.Age.class);
-]]></script>
-</div></div><p>And the same in XML DSL:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<from
uri="direct:inPojoAgeView"/>
+</plain-text-body><p>And the same in XML DSL:</p><parameter
ac:name="language">xml</parameter><plain-text-body><from
uri="direct:inPojoAgeView"/>
<marshal>
- <json library="Jackson"
unmarshalTypeName="org.apache.camel.component.jackson.TestPojoView"
jsonView="org.apache.camel.component.jackson.Views$Age"/>
+ <json library="Jackson"
unmarshalTypeName="org.apache.camel.component.jackson.TestPojoView"
jsonView="org.apache.camel.component.jackson.Views$Age"/>
</marshal>
-]]></script>
-</div></div><h3
id="JSON-SettingSerializationIncludeOptionforJacksonMarshal">Setting
Serialization Include Option for Jackson Marshal</h3><p><strong>Available as of
Camel 2.13.3/2.14</strong></p><p>If you want to marshal a POJO to JSON, and
the POJO has some fields with null values. And you want to skip these null
values, then you need to set either an annotation on the POJO, </p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[@JsonInclude(Include.NON_NULL)
+</plain-text-body><h3
id="JSON-SettingSerializationIncludeOptionforJacksonMarshal">Setting
Serialization Include Option for Jackson Marshal</h3><p><strong>Available as of
Camel 2.13.3/2.14</strong></p><p>If you want to marshal a POJO to JSON, and
the POJO has some fields with null values. And you want to skip these null
values, then you need to set either an annotation on the
POJO, </p><parameter
ac:name="language">java</parameter><plain-text-body>@JsonInclude(Include.NON_NULL)
public class MyPojo {
// ...
-}]]></script>
-</div></div><p>But this requires you to include that annotation in
your POJO source code. You can also configure the
Camel <strong><code>JsonDataFormat</code></strong> to set the include
option, as shown below:</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[JacksonDataFormat format = new
JacksonDataFormat();
-format.setInclude("NON_NULL");]]></script>
-</div></div><p>Or from XML DSL you configure this as</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dataFormats>
- <json id="json" library="Jackson"
include="NON_NULL"/>
-</dataFormats>]]></script>
-</div></div><h3
id="JSON-UnmarshalingfromJSONtoPOJOwithDynamicClassName">Unmarshaling from JSON
to POJO with Dynamic Class Name</h3><p><strong>Available as of Camel
2.14</strong></p><p>If you use Jackson to unmarshal JSON to POJO, then you can
now specify a header in the message that indicate which class name to unmarshal
to.<span style="line-height: 1.4285715;"> The header has key
</span><strong><code style="line-height:
1.4285715;">CamelJacksonUnmarshalType</code></strong><span style="line-height:
1.4285715;"> if that header is present in the message, then Jackson will
use that as FQN for the POJO class to unmarshal the JSON payload as. Notice
that behavior is enabled out of the box from <strong>Camel
2.14</strong>. </span></p><p><span style="line-height:
1.4285715;"> </span><span style="line-height: 1.4285715;">For JMS end
users there is the <strong><code>JMSType</code></strong> header from the
JMS spec that indicates that also. To enable support for <spa
n><strong><code>JMSType</code></strong></span> you would need to turn that on,
on the Jackson data format as shown:</span></p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[JacksonDataFormat format = new
JacksonDataFormat();
-format.setAllowJmsType(true);]]></script>
-</div></div><p>Or from XML DSL you configure this as</p><div class="code panel
pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dataFormats>
- <json id="json" library="Jackson"
allowJmsType="true"/>
-</dataFormats>]]></script>
-</div></div><h3
id="JSON-UnmarshalingFromJSONtoList<Map>orList<pojo>">Unmarshaling
From JSON to <code>List<Map></code>
or <code>List<pojo></code></h3><p><strong>Available as of Camel
2.14</strong></p><p>If you are using Jackson to unmarshal JSON to a list of
map/POJO, you can now specify this by
setting <strong><code>useList="true"</code></strong> or use
the <strong><code>org.apache.camel.component.jackson.ListJacksonDataFormat</code></strong>.</p><p>For
example, with Java you can do as shown below:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[JacksonDataFormat format = new
ListJacksonDataFormat();
+}</plain-text-body><p>But this requires you to include that annotation in
your POJO source code. You can also configure the
Camel <strong><code>JsonDataFormat</code></strong> to set the include
option, as shown below:</p><parameter
ac:name="language">java</parameter><plain-text-body>JacksonDataFormat format =
new JacksonDataFormat();
+format.setInclude("NON_NULL");</plain-text-body><p>Or from XML DSL you
configure this as</p><parameter
ac:name="language">xml</parameter><plain-text-body><dataFormats>
+ <json id="json" library="Jackson" include="NON_NULL"/>
+</dataFormats></plain-text-body><h3
id="JSON-UnmarshalingfromJSONtoPOJOwithDynamicClassName">Unmarshaling from JSON
to POJO with Dynamic Class Name</h3><p><strong>Available as of Camel
2.14</strong></p><p>If you use Jackson to unmarshal JSON to POJO, then you can
now specify a header in the message that indicate which class name to unmarshal
to.<span style="line-height: 1.4285715;"> The header has key
</span><strong><code style="line-height:
1.4285715;">CamelJacksonUnmarshalType</code></strong><span style="line-height:
1.4285715;"> if that header is present in the message, then Jackson will
use that as FQN for the POJO class to unmarshal the JSON payload as. Notice
that behavior is enabled out of the box from <strong>Camel
2.14</strong>. </span></p><p><span style="line-height:
1.4285715;"> </span><span style="line-height: 1.4285715;">For JMS end
users there is the <strong><code>JMSType</code></strong> header from the
JMS spec that indicates that also. To en
able support for <span><strong><code>JMSType</code></strong></span> you
would need to turn that on, on the Jackson data format as
shown:</span></p><parameter
ac:name="language">java</parameter><plain-text-body>JacksonDataFormat format =
new JacksonDataFormat();
+format.setAllowJmsType(true);</plain-text-body><p>Or from XML DSL you
configure this as</p><parameter
ac:name="language">xml</parameter><plain-text-body><dataFormats>
+ <json id="json" library="Jackson" allowJmsType="true"/>
+</dataFormats></plain-text-body><h3
id="JSON-UnmarshalingFromJSONtoList<Map>orList<pojo>">Unmarshaling
From JSON to <code>List<Map></code>
or <code>List<pojo></code></h3><p><strong>Available as of Camel
2.14</strong></p><p>If you are using Jackson to unmarshal JSON to a list of
map/POJO, you can now specify this by
setting <strong><code>useList="true"</code></strong> or use
the <strong><code>org.apache.camel.component.jackson.ListJacksonDataFormat</code></strong>.</p><p>For
example, with Java you can do as shown below:</p><parameter
ac:name="language">java</parameter><plain-text-body>JacksonDataFormat format =
new ListJacksonDataFormat();
// or
JacksonDataFormat format = new JacksonDataFormat();
format.useList();
// and you can specify the pojo class type also
-format.setUnmarshalType(MyPojo.class);]]></script>
-</div></div><p>And if you use XML DSL then you configure to use list using
<code>useList</code> attribute as shown below:</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dataFormats>
- <json id="json" library="Jackson"
useList="true"/>
-</dataFormats>]]></script>
-</div></div><p>And you can specify the pojo type also</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dataFormats>
- <json id="json" library="Jackson"
useList="true" unmarshalTypeName="com.foo.MyPojo"/>
-</dataFormats>]]></script>
-</div></div><h3 id="JSON-UsingCustomJackson'sObjectMapper">Using Custom
Jackson's <code>ObjectMapper</code></h3><p><strong>Available from Camel
2.17</strong></p><p>You can use custom
Jackson <strong><code>ObjectMapper</code></strong> instance, can be
configured as shown below.</p><div class="code panel pdl" style="border-width:
1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dataFormats>
- <json id="json" library="Jackson"
objectMapper="myMapper"/>
-</dataFormats>]]></script>
-</div></div><p>Where <strong><code>myMapper</code></strong> is the id of
the custom instance that Camel will lookup in the <a shape="rect"
href="registry.html">Registry.</a></p><h3
id="JSON-UsingCustomJacksonModules">Using Custom Jackson
Modules</h3><p><strong>Available as of Camel 2.15</strong></p><p>You can use
custom Jackson modules by specifying the class names of those using
the <strong><code>moduleClassNames</code></strong> option as shown
below.</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dataFormats>
- <json id="json" library="Jackson"
useList="true" unmarshalTypeName="com.foo.MyPojo"
moduleClassNames="com.foo.MyModule,com.foo.MyOtherModule"/>
-</dataFormats>]]></script>
-</div></div><p>When using <strong><code>moduleClassNames</code></strong>
then the custom Jackson modules are not configured, by created using default
constructor and used as-is. If a custom module needs any custom configuration,
then an instance of the module can be created and configured, and then
use <strong><code>modulesRefs</code></strong> to refer to the module as
shown below:</p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<bean id="myJacksonModule"
class="com.foo.MyModule">
+format.setUnmarshalType(MyPojo.class);</plain-text-body><p>And if you use XML
DSL then you configure to use list using <code>useList</code> attribute as
shown below:</p><parameter
ac:name="language">xml</parameter><plain-text-body><dataFormats>
+ <json id="json" library="Jackson" useList="true"/>
+</dataFormats></plain-text-body><p>And you can specify the pojo type
also</p><parameter
ac:name="language">xml</parameter><plain-text-body><dataFormats>
+ <json id="json" library="Jackson" useList="true"
unmarshalTypeName="com.foo.MyPojo"/>
+</dataFormats></plain-text-body><h3
id="JSON-UsingCustomJackson'sObjectMapper">Using Custom Jackson's
<code>ObjectMapper</code></h3><p><strong>Available from Camel
2.17</strong></p><p>You can use custom
Jackson <strong><code>ObjectMapper</code></strong> instance, can be
configured as shown below.</p><parameter
ac:name="language">xml</parameter><plain-text-body><dataFormats>
+ <json id="json" library="Jackson" objectMapper="myMapper"/>
+</dataFormats></plain-text-body><p>Where <strong><code>myMapper</code></strong>
is the id of the custom instance that Camel will lookup in the <a
shape="rect" href="registry.html">Registry.</a></p><h3
id="JSON-UsingCustomJacksonModules">Using Custom Jackson
Modules</h3><p><strong>Available as of Camel 2.15</strong></p><p>You can use
custom Jackson modules by specifying the class names of those using
the <strong><code>moduleClassNames</code></strong> option as shown
below.</p><parameter
ac:name="language">xml</parameter><plain-text-body><dataFormats>
+ <json id="json" library="Jackson" useList="true"
unmarshalTypeName="com.foo.MyPojo"
moduleClassNames="com.foo.MyModule,com.foo.MyOtherModule"/>
+</dataFormats></plain-text-body><p>When
using <strong><code>moduleClassNames</code></strong> then the custom
Jackson modules are not configured, by created using default constructor and
used as-is. If a custom module needs any custom configuration, then an instance
of the module can be created and configured, and then
use <strong><code>modulesRefs</code></strong> to refer to the module as
shown below:</p><parameter
ac:name="language">xml</parameter><plain-text-body><bean
id="myJacksonModule" class="com.foo.MyModule">
... // configure the module as you want
</bean>
-Â
+ 
<dataFormats>
- <json id="json" library="Jackson"
useList="true" unmarshalTypeName="com.foo.MyPojo"
moduleRefs="myJacksonModule"/>
-</dataFormats>]]></script>
-</div></div><p> Multiple modules can be specified separated by comma,
such as
<strong><code>moduleRefs="myJacksonModule,myOtherModule"</code></strong>.</p><h3
id="JSON-EnablingorDisableFeaturesUsingJackson">Enabling or Disable Features
Using Jackson</h3><p><strong>Available as of Camel 2.15</strong></p><p>Jackson
has a number of features you can enable or disable, which
its <strong><code>ObjectMapper</code></strong> uses. For example to
disable failing on unknown properties when marshaling, you can configure this
using the <strong><code>disableFeatures</code></strong>:</p><div class="code
panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dataFormats>
- <json id="json" library="Jackson"
unmarshalTypeName="com.foo.MyPojo"
disableFeatures="FAIL_ON_UNKNOWN_PROPERTIES"/>
-</dataFormats>]]></script>
-</div></div><p>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</p><ul><li><code>com.fasterxml.jackson.databind.SerializationFeature</code></li><li><code>com.fasterxml.jackson.databind.DeserializationFeature</code></li><li><code>com.fasterxml.jackson.databind.MapperFeature</code></li></ul><p>To
enable a feature use the <strong><code>enableFeatures</code></strong>
options instead.</p><p>From Java code you can use the type safe methods
from <strong><code>camel-jackson</code></strong> module:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[JacksonDataFormat df = new
JacksonDataFormat(MyPojo.class);
+ <json id="json" library="Jackson" useList="true"
unmarshalTypeName="com.foo.MyPojo" moduleRefs="myJacksonModule"/>
+</dataFormats></plain-text-body><p> Multiple modules can be
specified separated by comma, such as
<strong><code>moduleRefs="myJacksonModule,myOtherModule"</code></strong>.</p><h3
id="JSON-EnablingorDisableFeaturesUsingJackson">Enabling or Disable Features
Using Jackson</h3><p><strong>Available as of Camel 2.15</strong></p><p>Jackson
has a number of features you can enable or disable, which
its <strong><code>ObjectMapper</code></strong> uses. For example to
disable failing on unknown properties when marshaling, you can configure this
using the <strong><code>disableFeatures</code></strong>:</p><parameter
ac:name="language">xml</parameter><plain-text-body><dataFormats>
+ <json id="json" library="Jackson" unmarshalTypeName="com.foo.MyPojo"
disableFeatures="FAIL_ON_UNKNOWN_PROPERTIES"/>
+</dataFormats></plain-text-body><p>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</p><ul><li><code>com.fasterxml.jackson.databind.SerializationFeature</code></li><li><code>com.fasterxml.jackson.databind.DeserializationFeature</code></li><li><code>com.fasterxml.jackson.databind.MapperFeature</code></li></ul><p>To
enable a feature use the <strong><code>enableFeatures</code></strong>
options instead.</p><p>From Java code you can use the type safe methods
from <strong><code>camel-jackson</code></strong> module:</p><parameter
ac:name="language">java</parameter><plain-text-body>JacksonDataFormat df = new
JacksonDataFormat(MyPojo.class);
df.disableFeature(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
-df.disableFeature(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);]]></script>
-</div></div><h3 id="JSON-ConvertingMapstoPOJOUsingJackson">Converting Maps to
POJO Using Jackson</h3><p>Available since <strong>Camel 2.16</strong>. Jackson
<strong><code>ObjectMapper</code></strong> can be used to convert maps to POJO
objects. Jackson component comes with the data converter that can be used to
convert <strong><code>java.util.Map</code></strong> instance to non-String,
non-primitive and non-Number objects.</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[Map<String, Object> invoiceData = new
HashMap<String, Object>();
-invoiceData.put("netValue", 500);
-producerTemplate.sendBody("direct:mapToInvoice", invoiceData);
+df.disableFeature(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);</plain-text-body><h3
id="JSON-ConvertingMapstoPOJOUsingJackson">Converting Maps to POJO Using
Jackson</h3><p>Available since <strong>Camel 2.16</strong>. Jackson
<strong><code>ObjectMapper</code></strong> can be used to convert maps to POJO
objects. Jackson component comes with the data converter that can be used to
convert <strong><code>java.util.Map</code></strong> instance to non-String,
non-primitive and non-Number objects.</p><parameter
ac:name="language">java</parameter><plain-text-body>Map<String, Object>
invoiceData = new HashMap<String, Object>();
+invoiceData.put("netValue", 500);
+producerTemplate.sendBody("direct:mapToInvoice", invoiceData);
...
// Later in the processor
-Invoice invoice = exchange.getIn().getBody(Invoice.class);]]></script>
-</div></div><p>If there is a single <strong><code>ObjectMapper</code></strong>
instance available in the Camel registry, it will used by the converter to
perform the conversion. Otherwise the default mapper will be used.
 </p><h3 id="JSON-FormattedJSONmarshalling(pretty-printing)">Formatted
JSON marshalling (pretty-printing)</h3><p><strong>Available as of Camel
2.16</strong></p><p>Using the <strong><code>prettyPrint</code></strong>
option one can output a well formatted JSON while marshaling:</p><div
class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dataFormats>
- <json id="xstream" prettyPrint="true"/>
- <json id="jackson" prettyPrint="true"
library="Jackson"/>
- <json id="gson" prettyPrint="true"
library="Gson"/>
-</dataFormats>]]></script>
-</div></div><p><span style="line-height: 1.5625;">And in Java
DSL:</span></p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[from("direct:inPretty").marshal().json(true);
-Â
-from("direct:inPretty").marshal().json(JsonLibrary.Jackson, true);
-Â
-from("direct:inPretty").marshal().json(JsonLibrary.Gson,
true);]]></script>
-</div></div><p><span style="line-height: 1.5625;">Please note that as of Camel
2.16 there are five different overloaded <strong><code>json()</code></strong>
DSL methods which support the <strong><code>prettyPrint</code></strong> option
in combination with other settings for
<strong><code>JsonLibrary</code></strong>,
<strong><code>unmarshalType</code></strong>,
<strong><code>jsonView</code></strong> etc. </span></p><h3
id="JSON-IntegratingJacksonwithCamel'sTypeConverters"><span style="line-height:
1.5625;"> </span>Integrating Jackson with
Camel's TypeConverters</h3><h3 id="JSON-AvailableasofCamel2.17"><span
style="line-height: 1.5625;"> </span><strong>Available as of Camel
2.17</strong></h3><p><span style="line-height:
1.5625;">The <strong><code>camel-jackson</code></strong> module allows to
integrate Jackson as a <a shape="rect" href="type-converter.html">Type
Converter</a> in the Camel registry. This works in similar ways
that <strong><code>camel-
jaxb</code></strong> integrates with the type converter as well.
However <strong><code>camel-jackson</code></strong> must be explicit
enabled, which is done by setting some options on
the <strong><code>CamelContext</code></strong> properties, as shown
below:</span></p><div class="code panel pdl" style="border-width: 1px;"><div
class="codeContent panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[// Enable Jackson JSON type converter.
-getContext().getProperties().put("CamelJacksonEnableTypeConverter",
"true");
+Invoice invoice =
exchange.getIn().getBody(Invoice.class);</plain-text-body><p>If there is a
single <strong><code>ObjectMapper</code></strong> instance available in the
Camel registry, it will used by the converter to perform the conversion.
Otherwise the default mapper will be used.  </p><h3
id="JSON-FormattedJSONmarshalling(pretty-printing)">Formatted JSON marshalling
(pretty-printing)</h3><p><strong>Available as of Camel
2.16</strong></p><p>Using the <strong><code>prettyPrint</code></strong>
option one can output a well formatted JSON while
marshaling:</p><parameter
ac:name="language">xml</parameter><plain-text-body><dataFormats>
+ <json id="xstream" prettyPrint="true"/>
+ <json id="jackson" prettyPrint="true" library="Jackson"/>
+ <json id="gson" prettyPrint="true" library="Gson"/>
+</dataFormats></plain-text-body><p><span style="line-height:
1.5625;">And in Java DSL:</span></p><parameter
ac:name="language">java</parameter><plain-text-body>from("direct:inPretty").marshal().json(true);
+ 
+from("direct:inPretty").marshal().json(JsonLibrary.Jackson, true);
+ 
+from("direct:inPretty").marshal().json(JsonLibrary.Gson,
true);</plain-text-body><p><span style="line-height: 1.5625;">Please note that
as of Camel 2.16 there are five different overloaded
<strong><code>json()</code></strong> DSL methods which support the
<strong><code>prettyPrint</code></strong> option in combination with other
settings for <strong><code>JsonLibrary</code></strong>,
<strong><code>unmarshalType</code></strong>,
<strong><code>jsonView</code></strong> etc. </span></p><h3
id="JSON-IntegratingJacksonwithCamel'sTypeConverters"><span style="line-height:
1.5625;"> </span>Integrating Jackson with
Camel's TypeConverters</h3><h3 id="JSON-AvailableasofCamel2.17"><span
style="line-height: 1.5625;"> </span><strong>Available as of Camel
2.17</strong></h3><p><span style="line-height:
1.5625;">The <strong><code>camel-jackson</code></strong> module allows to
integrate Jackson as a <a shape="rect" href="type-converter.html">Type
Converter</a> in the Came
l registry. This works in similar ways
that <strong><code>camel-jaxb</code></strong> integrates with the
type converter as well.
However <strong><code>camel-jackson</code></strong> must be explicit
enabled, which is done by setting some options on
the <strong><code>CamelContext</code></strong> properties, as shown
below:</span></p><parameter
ac:name="language">java</parameter><plain-text-body>// Enable Jackson JSON type
converter.
+getContext().getProperties().put("CamelJacksonEnableTypeConverter", "true");
// Allow Jackson JSON to convert to pojo types also (by default Jackson only
converts to String and other simple types).
-getContext().getProperties().put("CamelJacksonTypeConverterToPojo",
"true");]]></script>
-</div></div><p>The <strong><code>camel-jackson</code></strong> type
converter integrates with JAXB which means you can annotate POJO class
with JAXB annotations that Jackson can leverage. </p><h3
id="JSON-DependenciesforXStream"><span style="line-height:
1.5625;">Dependencies for XStream</span></h3><p>To use JSON in your camel
routes you need to add the a dependency
on <strong><code>camel-xstream</code></strong> which implements this data
format.</p><p>If you use maven you could just add the following to your
<strong><code>pom.xml</code></strong>, substituting the version number for the
latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+getContext().getProperties().put("CamelJacksonTypeConverterToPojo",
"true");</plain-text-body><p>The <strong><code>camel-jackson</code></strong>
type converter integrates with JAXB which means you can annotate POJO class
with JAXB annotations that Jackson can leverage. </p><h3
id="JSON-DependenciesforXStream"><span style="line-height:
1.5625;">Dependencies for XStream</span></h3><p>To use JSON in your camel
routes you need to add the a dependency
on <strong><code>camel-xstream</code></strong> which implements this data
format.</p><p>If you use maven you could just add the following to your
<strong><code>pom.xml</code></strong>, substituting the version number for the
latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><parameter
ac:name="language">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xstream</artifactId>
<version>2.9.2</version>
</dependency>
-]]></script>
-</div></div><h3 id="JSON-DependenciesforJackson">Dependencies for
Jackson</h3><p>To use JSON in your camel routes you need to add the a
dependency on <strong><code>camel-jackson</code></strong> which implements
this data format.</p><p>If you use maven you could just add the following to
your <strong><code>pom.xml</code></strong>, substituting the version number for
the latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+</plain-text-body><h3 id="JSON-DependenciesforJackson">Dependencies for
Jackson</h3><p>To use JSON in your camel routes you need to add the a
dependency on <strong><code>camel-jackson</code></strong> which implements
this data format.</p><p>If you use maven you could just add the following to
your <strong><code>pom.xml</code></strong>, substituting the version number for
the latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><parameter
ac:name="language">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>2.9.2</version>
</dependency>
-]]></script>
-</div></div><h3 id="JSON-DependenciesforGSON">Dependencies for GSON</h3><p>To
use JSON in your camel routes you need to add the a dependency
on <strong><code>camel-gson</code></strong> which implements this data
format.</p><p>If you use maven you could just add the following to your
<strong><code>pom.xml</code></strong>, substituting the version number for the
latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><div class="code panel pdl"
style="border-width: 1px;"><div class="codeContent panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
+</plain-text-body><h3 id="JSON-DependenciesforGSON">Dependencies for
GSON</h3><p>To use JSON in your camel routes you need to add the a dependency
on <strong><code>camel-gson</code></strong> which implements this data
format.</p><p>If you use maven you could just add the following to your
<strong><code>pom.xml</code></strong>, substituting the version number for the
latest & greatest release (see <a shape="rect" href="download.html">the
download page for the latest versions</a>).</p><parameter
ac:name="language">xml</parameter><plain-text-body><dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-gson</artifactId>
<version>2.10.0</version>
</dependency>
-]]></script>
-</div></div></div>
+</plain-text-body></div>
</td>
<td valign="top">
<div class="navigation">
Modified: websites/production/camel/content/jxpath.html
==============================================================================
--- websites/production/camel/content/jxpath.html (original)
+++ websites/production/camel/content/jxpath.html Fri Aug 25 08:22:01 2017
@@ -36,17 +36,6 @@
<![endif]-->
- <link href='//camel.apache.org/styles/highlighter/styles/shCoreCamel.css'
rel='stylesheet' type='text/css' />
- <link href='//camel.apache.org/styles/highlighter/styles/shThemeCamel.css'
rel='stylesheet' type='text/css' />
- <script src='//camel.apache.org/styles/highlighter/scripts/shCore.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushJava.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushXml.js'
type='text/javascript'></script>
- <script src='//camel.apache.org/styles/highlighter/scripts/shBrushPlain.js'
type='text/javascript'></script>
-
- <script type="text/javascript">
- SyntaxHighlighter.defaults['toolbar'] = false;
- SyntaxHighlighter.all();
- </script>
<title>
Apache Camel: JXPath
@@ -92,13 +81,11 @@
<p>You can use XPath expressions directly using smart completion in your IDE
as follows</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("queue:foo").filter().
- jxpath("/in/body/foo").
- to("queue:bar")
-]]></script>
-</div></div>
+<plain-text-body>
+from("queue:foo").filter().
+ jxpath("/in/body/foo").
+ to("queue:bar")
+</plain-text-body>
<h3 id="JXPath-Variables">Variables</h3>
@@ -115,38 +102,30 @@ from("queue:foo").filter().
<p>If you prefer to configure your routes in your <a shape="rect"
href="spring.html">Spring</a> XML file then you can use JXPath expressions as
follows</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
+<parameter ac:name="lang">xml</parameter><plain-text-body>
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
- http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
+ http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
- <camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
+ <camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
<route>
- <from uri="activemq:MyQueue"/>
+ <from uri="activemq:MyQueue"/>
<filter>
- <jxpath>in/body/name = 'James'</xpath>
- <to uri="mqseries:SomeOtherQueue"/>
+ <jxpath>in/body/name = 'James'</xpath>
+ <to uri="mqseries:SomeOtherQueue"/>
</filter>
</route>
</camelContext>
</beans>
-]]></script>
-</div></div>
+</plain-text-body>
<h3 id="JXPath-Examples">Examples</h3>
<p>Here is a simple <a shape="rect" class="external-link"
href="http://svn.apache.org/repos/asf/camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterTest.java">example</a>
using a JXPath expression as a predicate in a <a shape="rect"
href="message-filter.html">Message Filter</a></p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-from("direct:start").
- filter().jxpath("in/body/name='James'").
- to("mock:result");
-]]></script>
-</div></div>
+<plain-text-body>{snippet:id=example|lang=java|url=camel/trunk/components/camel-jxpath/src/test/java/org/apache/camel/language/jxpath/JXPathFilterTest.java}</plain-text-body>
<h2 id="JXPath-JXPathinjection">JXPath injection </h2>
@@ -154,17 +133,15 @@ from("direct:start").
<p>For example</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+<plain-text-body>
public class Foo {
- @MessageDriven(uri = "activemq:my.queue")
- public void doSomething(@JXPath("in/body/foo") String
correlationID, @Body String body) {
+ @MessageDriven(uri = "activemq:my.queue")
+ public void doSomething(@JXPath("in/body/foo") String correlationID, @Body
String body) {
// process the inbound message here
}
}
-]]></script>
-</div></div>
+</plain-text-body>
<h3 id="JXPath-Loadingscriptfromexternalresource">Loading script from external
resource</h3>
@@ -172,11 +149,9 @@ public class Foo {
<p>You can externalize the script and have Camel load it from a resource such
as <code>"classpath:"</code>, <code>"file:"</code>, or <code>"http:"</code>.<br
clear="none">
This is done using the following syntax:
<code>"resource:scheme:location"</code>, eg to refer to a file on the classpath
you can do:</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
-.setHeader("myHeader").jxpath("resource:classpath:myjxpath.txt")
-]]></script>
-</div></div>
+<plain-text-body>
+.setHeader("myHeader").jxpath("resource:classpath:myjxpath.txt")
+</plain-text-body>
<h3 id="JXPath-Dependencies">Dependencies</h3>
@@ -185,15 +160,13 @@ This is done using the following syntax:
<p>If you use maven you could just add the following to your pom.xml,
substituting the version number for the latest & greatest release (see <a
shape="rect" href="download.html">the download page for the latest
versions</a>).</p>
-<div class="code panel pdl" style="border-width: 1px;"><div class="codeContent
panelContent pdl">
-<script class="brush: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[
+<plain-text-body>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jxpath</artifactId>
<version>x.x.x</version>
</dependency>
-]]></script>
-</div></div>
+</plain-text-body>
<p>Otherwise, you'll also need <a shape="rect" class="external-link"
href="http://repo2.maven.org/maven2/commons-jxpath/commons-jxpath/1.3/commons-jxpath-1.3.jar"
rel="nofollow">Commons JXPath</a>.</p></div>
</td>