You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by bu...@apache.org on 2015/10/12 00:19:11 UTC

svn commit: r968545 - in /websites/production/camel/content: cache/main.pageCache jackson-xml.html

Author: buildbot
Date: Sun Oct 11 22:19:10 2015
New Revision: 968545

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 22:19:10 2015
@@ -41,6 +41,7 @@
   <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;
@@ -90,6 +91,47 @@
   unmarshal().jacksonxml().
   to(&quot;mqseries:Another.Queue&quot;);
 ]]></script>
+</div></div><h4 id="JacksonXML-UsingJacksonXMLinSpringDSL">Using Jackson XML in Spring DSL</h4><p>When using&#160;<a shape="rect" href="data-format.html">Data Format</a>&#160;in Spring DSL you need to declare the data formats first. This is done in the&#160;<strong>DataFormats</strong>&#160;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[        &lt;dataFormats&gt;
+            &lt;!-- 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 --&gt;
+            &lt;jacksonxml id=&quot;jack&quot; unmarshalTypeName=&quot;org.apache.camel.component.jacksonxml.TestPojo&quot;/&gt;
+        &lt;/dataFormats&gt;
+]]></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[       &lt;route&gt;
+            &lt;from uri=&quot;direct:back&quot;/&gt;
+            &lt;unmarshal ref=&quot;jack&quot;/&gt;
+            &lt;to uri=&quot;mock:reverse&quot;/&gt;
+        &lt;/route&gt;
+]]></script>
+</div></div><h3 id="JacksonXML-ExcludingPOJOfieldsfrommarshalling">Excluding POJO fields from marshalling</h3><p>When marshalling a POJO to JSON you might want to exclude certain fields from the JSON output. With Jackson you can use&#160;<a shape="rect" class="external-link" href="http://wiki.fasterxml.com/JacksonJsonViews" rel="nofollow">JSON views</a>&#160;to accomplish this. 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>Use the marker classes with the&#160;<code>@JsonView</code>&#160;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&#160;<code>JacksonXMLDataFormat</code>&#160;to marshall the above POJO to XML.<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(&quot;direct:inPojoAgeView&quot;).marshal().jacksonxml(TestPojoView.class, Views.Age.class);
+]]></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[{&quot;age&quot;:30, &quot;weight&quot;: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 &amp; 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[&lt;dependency&gt;
   &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;