Author: buildbot
Date: Sun Oct 11 23:19:22 2015
New Revision: 968549
Log:
Production update by buildbot for camel
Modified:
websites/production/camel/content/cache/main.pageCache
websites/production/camel/content/jackson-xml.html
Modified: websites/production/camel/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.
Modified: websites/production/camel/content/jackson-xml.html
==============================================================================
--- websites/production/camel/content/jackson-xml.html (original)
+++ websites/production/camel/content/jackson-xml.html Sun Oct 11 23:19:22 2015
@@ -132,7 +132,89 @@ from("direct:inPojoAgeView").m
]]></script>
</div></div>Note that the weight 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><h3 id="JacksonXML-Dependencies">Dependencies</h3><p>To use
Jackson XML in your camel routes you need to add the dependency on
<strong>camel-jacksonxml</strong> which implements this data format.</p><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">
+</div></div><h3
id="JacksonXML-Include/ExcludefieldsusingthejsonViewattributewithJacksonXMLDataFormat">Include/Exclude
fields using the <code>jsonView</code> attribute
with <code>JacksonXML</code>DataFormat</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[JacksonXMLDataFormat ageViewFormat = new
JacksonXMLDataFormat(TestPojoView.class, Views.Age.class);
+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").
+ marshal().jacksonxml(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"/>
+ <marshal>
+ <jacksonxml
unmarshalTypeName="org.apache.camel.component.jacksonxml.TestPojoView"
jsonView="org.apache.camel.component.jacksonxml.Views$Age"/>
+ </marshal>
+]]></script>
+</div></div><h3 id="JacksonXML-Settingserializationincludeoption">Setting
serialization include option</h3><p>If you want to marshal a pojo to XML, 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)
+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 JacksonXMLDataFormat 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[JacksonXMLDataFormat format = new
JacksonXMLDataFormat();
+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: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <dataFormats>
+ <jacksonxml id="json" include="NOT_NULL"/>
+ </dataFormats>]]></script>
+</div></div><h3
id="JacksonXML-UnmarshallingfromXMLtoPOJOwithdynamicclassname">Unmarshalling
from XML to POJO with dynamic class name</h3><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.<br clear="none"><span>The header has
key </span><code>CamelJacksonUnmarshalType</code><span> if that
header is present in the message, then Jackson will use that as FQN for the
POJO class to unmarshal the XML payload
as.</span></p><p><span> </span><span>For JMS end users there is the
JMSType header from the JMS spec that indicates that also. To enable support
for JMSType 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: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <dataFormats>
+ <jacksonxml id="json" allowJmsType="true"/>
+ </dataFormats>]]></script>
+</div></div><h3
id="JacksonXML-UnmarshallingfromjsontoList<Map>orList<pojo>">Unmarshalling
from json to List<Map> or List<pojo></h3><p>If you are using
Jackson to unmarshal XML to a list of map/pojo, you can now specify this by
setting <code>useList="true"</code> or use
the <code>org.apache.camel.component.jacksonxml.ListJacksonXMLDataFormat</code>.
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[JacksonXMLDataFormat format = new
ListJacksonXMLDataFormat();
+// or
+JacksonXMLDataFormat format = new JacksonXMLDataFormat();
+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: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <dataFormats>
+ <jacksonxml id="jack" 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: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <dataFormats>
+ <jacksonxml id="jack" useList="true"
unmarshalTypeName="com.foo.MyPojo"/>
+ </dataFormats>]]></script>
+</div></div><h3 id="JacksonXML-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
moduleClassNames 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[ <dataFormats>
+ <jacksonxml id="jack" useList="true"
unmarshalTypeName="com.foo.MyPojo"
moduleClassNames="com.foo.MyModule,com.foo.MyOtherModule"/>
+ </dataFormats>]]></script>
+</div></div><p>When using moduleClassNames 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 modulesRefs 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: java; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[ <bean id="myJacksonModule"
class="com.foo.MyModule">
+ ... // configure the module as you want
+ </bean>
+Â
+ <dataFormats>
+ <jacksonxml id="json" useList="true"
unmarshalTypeName="com.foo.MyPojo"
moduleRefs="myJacksonModule"/>
+ </dataFormats>]]></script>
+</div></div><p> Multiple modules can be specified separated by comma,
such as moduleRefs="myJacksonModule,myOtherModule"</p><h3
id="JacksonXML-EnablingordisablefeaturesusingJackson">Enabling or disable
features using Jackson</h3><p>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:</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[ <dataFormats>
+ <jacksonxml id="json"
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>com.fasterxml.jackson.databind.SerializationFeature</li><li>com.fasterxml.jackson.databind.DeserializationFeature</li><li>com.fasterxml.jackson.databind.MapperFeature</li></ul><p>To
enable a feature use the enableFeatures options instead.</p><p>From Java code
you can use the type safe methods from camel-jackson 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);
+df.disableFeature(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
+df.disableFeature(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES);]]></script>
+</div></div><h3 id="JacksonXML-ConvertingMapstoPOJOusingJackson">Converting
Maps to POJO using
Jackson</h3><p>Jackson <code>ObjectMapper</code> can be used to
convert maps to POJO objects. Jackson component comes with the data converter
that can be used to convert <code>java.util.Map</code> 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);
+...
+// Later in the processor
+Invoice invoice = exchange.getIn().getBody(Invoice.class);]]></script>
+</div></div><p>If there is a
single <code>ObjectMapper</code> 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="JacksonXML-FormattedXMLmarshalling(pretty-printing)">Formatted XML
marshalling (pretty-printing)</h3><p>Using
the <code>prettyPrint</code> option one can output a well
formatted JSON while marshalling:</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[ <dataFormats>
+ <jacksonxml id="jack" prettyPrint="true"/>
+ </dataFormats>]]></script>
+</div></div><p><span>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().jacksonxml(true);]]></script>
+</div></div><p><span>Please note that as of Camel 2.16 there are 5 different
overloaded <code>jacksonxml()</code> DSL methods which support
the <code>prettyPrint</code> option in combination with other
settings
for <code>unmarshalType</code>, <code>jsonView</code> etc. </span></p><h3
id="JacksonXML-Dependencies">Dependencies</h3><p>To use Jackson XML in your
camel routes you need to add the dependency on
<strong>camel-jacksonxml</strong> which implements this data format.</p><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: xml; gutter: false; theme: Default"
type="syntaxhighlighter"><![CDATA[<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jacksonxml</artifactId>