camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r811164 - in /websites/production/camel/content: book-dataformat-appendix.html book-in-one-page.html cache/main.pageCache json.html
Date Mon, 02 Apr 2012 20:22:03 GMT
Author: buildbot
Date: Mon Apr  2 20:22:02 2012
New Revision: 811164

Log:
Production update by buildbot for camel

Modified:
    websites/production/camel/content/book-dataformat-appendix.html
    websites/production/camel/content/book-in-one-page.html
    websites/production/camel/content/cache/main.pageCache
    websites/production/camel/content/json.html

Modified: websites/production/camel/content/book-dataformat-appendix.html
==============================================================================
--- websites/production/camel/content/book-dataformat-appendix.html (original)
+++ websites/production/camel/content/book-dataformat-appendix.html Mon Apr  2 20:22:02 2012
@@ -852,7 +852,7 @@ Camel provides integration with two popu
 
 <p>By default Camel uses the XStream library. </p>
 
-<h3><a shape="rect" name="BookDataFormatAppendix-UsingJSondataformatwiththeXStreamlibrary"></a>Using
JSon data format with the XStream library</h3>
+<h3><a shape="rect" name="BookDataFormatAppendix-UsingJsondataformatwiththeXStreamlibrary"></a>Using
Json data format with the XStream library</h3>
 <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
 <pre class="code-java">
 <span class="code-comment">// lets turn <span class="code-object">Object</span>
messages into json then send to MQSeries
@@ -906,6 +906,69 @@ Camel provides integration with two popu
 </pre>
 </div></div>
 
+<h3><a shape="rect" name="BookDataFormatAppendix-ExcludingPOJOfieldsfrommarshalling"></a>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 <a shape="rect" class="external-link" href="http://wiki.fasterxml.com/JacksonJsonViews"
rel="nofollow">JSON views</a> to accomplish this. First create one or more marker
classes.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java"><span class="code-keyword">public</span> class Views
{
+
+    <span class="code-keyword">static</span> class Weight { }
+    <span class="code-keyword">static</span> class Age { }
+}
+</pre>
+</div></div>
+
+<p>Use the marker classes with the <tt>@JsonView</tt> annotation to include/exclude
certain fields. The annotation also works on getters.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">@JsonView(Views.Age.class)
+<span class="code-keyword">private</span> <span class="code-object">int</span>
age = 30;
+
+<span class="code-keyword">private</span> <span class="code-object">int</span>
height = 190;
+
+@JsonView(Views.Weight.class)
+<span class="code-keyword">private</span> <span class="code-object">int</span>
weight = 70;
+</pre>
+</div></div>
+
+<p>Finally use the Camel <tt>JacksonDataFormat</tt> to marshall the above
POJO to JSON.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">JacksonDataFormat ageViewFormat = <span class="code-keyword">new</span>
JacksonDataFormat(TestPojoView.class, Views.Age.class);
+</pre>
+</div></div>
+
+<p>Note that the weight field in missing in the resulting JSON:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+{<span class="code-quote">"age"</span>:30, <span class="code-quote">"height"</span>:190}
+</pre>
+</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" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">/**
+ * Strategy to exclude {@link ExcludeAge} annotated fields
+ */
+<span class="code-keyword">protected</span> <span class="code-keyword">static</span>
class AgeExclusionStrategy <span class="code-keyword">implements</span> ExclusionStrategy
{
+
+    @Override
+    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
shouldSkipField(FieldAttributes f) {
+        <span class="code-keyword">return</span> f.getAnnotation(ExcludeAge.class)
!= <span class="code-keyword">null</span>;
+    }
+
+    @Override
+    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
shouldSkipClass(<span class="code-object">Class</span>&lt;?&gt; clazz)
{
+        <span class="code-keyword">return</span> <span class="code-keyword">false</span>;
+    }
+}
+</pre>
+</div></div>
+
+<p>The <tt>GsonDataFormat</tt> accepts an <tt>ExclusionStrategy</tt>
in its constructor:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">GsonDataFormat ageExclusionFormat = <span class="code-keyword">new</span>
GsonDataFormat(TestPojoExclusion.class, <span class="code-keyword">new</span>
AgeExclusionStrategy());
+</pre>
+</div></div>
+<p>The line above will exclude fields annotated with <tt>@ExcludeAge</tt>
during JSON marshalling.</p>
+
 <h3><a shape="rect" name="BookDataFormatAppendix-DependenciesforXStream"></a>Dependencies
for XStream</h3>
 
 <p>To use JSON in your camel routes you need to add the a dependency on <b>camel-xstream</b>
which implements this data format. </p>

Modified: websites/production/camel/content/book-in-one-page.html
==============================================================================
--- websites/production/camel/content/book-in-one-page.html (original)
+++ websites/production/camel/content/book-in-one-page.html Mon Apr  2 20:22:02 2012
@@ -11661,7 +11661,7 @@ Camel provides integration with two popu
 
 <p>By default Camel uses the XStream library. </p>
 
-<h3><a shape="rect" name="BookInOnePage-UsingJSondataformatwiththeXStreamlibrary"></a>Using
JSon data format with the XStream library</h3>
+<h3><a shape="rect" name="BookInOnePage-UsingJsondataformatwiththeXStreamlibrary"></a>Using
Json data format with the XStream library</h3>
 <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
 <pre class="code-java">
 <span class="code-comment">// lets turn <span class="code-object">Object</span>
messages into json then send to MQSeries
@@ -11715,6 +11715,69 @@ Camel provides integration with two popu
 </pre>
 </div></div>
 
+<h3><a shape="rect" name="BookInOnePage-ExcludingPOJOfieldsfrommarshalling"></a>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 <a shape="rect" class="external-link" href="http://wiki.fasterxml.com/JacksonJsonViews"
rel="nofollow">JSON views</a> to accomplish this. First create one or more marker
classes.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java"><span class="code-keyword">public</span> class Views
{
+
+    <span class="code-keyword">static</span> class Weight { }
+    <span class="code-keyword">static</span> class Age { }
+}
+</pre>
+</div></div>
+
+<p>Use the marker classes with the <tt>@JsonView</tt> annotation to include/exclude
certain fields. The annotation also works on getters.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">@JsonView(Views.Age.class)
+<span class="code-keyword">private</span> <span class="code-object">int</span>
age = 30;
+
+<span class="code-keyword">private</span> <span class="code-object">int</span>
height = 190;
+
+@JsonView(Views.Weight.class)
+<span class="code-keyword">private</span> <span class="code-object">int</span>
weight = 70;
+</pre>
+</div></div>
+
+<p>Finally use the Camel <tt>JacksonDataFormat</tt> to marshall the above
POJO to JSON.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">JacksonDataFormat ageViewFormat = <span class="code-keyword">new</span>
JacksonDataFormat(TestPojoView.class, Views.Age.class);
+</pre>
+</div></div>
+
+<p>Note that the weight field in missing in the resulting JSON:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+{<span class="code-quote">"age"</span>:30, <span class="code-quote">"height"</span>:190}
+</pre>
+</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" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">/**
+ * Strategy to exclude {@link ExcludeAge} annotated fields
+ */
+<span class="code-keyword">protected</span> <span class="code-keyword">static</span>
class AgeExclusionStrategy <span class="code-keyword">implements</span> ExclusionStrategy
{
+
+    @Override
+    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
shouldSkipField(FieldAttributes f) {
+        <span class="code-keyword">return</span> f.getAnnotation(ExcludeAge.class)
!= <span class="code-keyword">null</span>;
+    }
+
+    @Override
+    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
shouldSkipClass(<span class="code-object">Class</span>&lt;?&gt; clazz)
{
+        <span class="code-keyword">return</span> <span class="code-keyword">false</span>;
+    }
+}
+</pre>
+</div></div>
+
+<p>The <tt>GsonDataFormat</tt> accepts an <tt>ExclusionStrategy</tt>
in its constructor:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">GsonDataFormat ageExclusionFormat = <span class="code-keyword">new</span>
GsonDataFormat(TestPojoExclusion.class, <span class="code-keyword">new</span>
AgeExclusionStrategy());
+</pre>
+</div></div>
+<p>The line above will exclude fields annotated with <tt>@ExcludeAge</tt>
during JSON marshalling.</p>
+
 <h3><a shape="rect" name="BookInOnePage-DependenciesforXStream"></a>Dependencies
for XStream</h3>
 
 <p>To use JSON in your camel routes you need to add the a dependency on <b>camel-xstream</b>
which implements this data format. </p>

Modified: websites/production/camel/content/cache/main.pageCache
==============================================================================
Binary files - no diff available.

Modified: websites/production/camel/content/json.html
==============================================================================
--- websites/production/camel/content/json.html (original)
+++ websites/production/camel/content/json.html Mon Apr  2 20:22:02 2012
@@ -87,7 +87,7 @@ Camel provides integration with two popu
 
 <p>By default Camel uses the XStream library. </p>
 
-<h3><a shape="rect" name="JSON-UsingJSondataformatwiththeXStreamlibrary"></a>Using
JSon data format with the XStream library</h3>
+<h3><a shape="rect" name="JSON-UsingJsondataformatwiththeXStreamlibrary"></a>Using
Json data format with the XStream library</h3>
 <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
 <pre class="code-java">
 <span class="code-comment">// lets turn <span class="code-object">Object</span>
messages into json then send to MQSeries
@@ -141,6 +141,69 @@ Camel provides integration with two popu
 </pre>
 </div></div>
 
+<h3><a shape="rect" name="JSON-ExcludingPOJOfieldsfrommarshalling"></a>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 <a shape="rect" class="external-link" href="http://wiki.fasterxml.com/JacksonJsonViews"
rel="nofollow">JSON views</a> to accomplish this. First create one or more marker
classes.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java"><span class="code-keyword">public</span> class Views
{
+
+    <span class="code-keyword">static</span> class Weight { }
+    <span class="code-keyword">static</span> class Age { }
+}
+</pre>
+</div></div>
+
+<p>Use the marker classes with the <tt>@JsonView</tt> annotation to include/exclude
certain fields. The annotation also works on getters.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">@JsonView(Views.Age.class)
+<span class="code-keyword">private</span> <span class="code-object">int</span>
age = 30;
+
+<span class="code-keyword">private</span> <span class="code-object">int</span>
height = 190;
+
+@JsonView(Views.Weight.class)
+<span class="code-keyword">private</span> <span class="code-object">int</span>
weight = 70;
+</pre>
+</div></div>
+
+<p>Finally use the Camel <tt>JacksonDataFormat</tt> to marshall the above
POJO to JSON.</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">JacksonDataFormat ageViewFormat = <span class="code-keyword">new</span>
JacksonDataFormat(TestPojoView.class, Views.Age.class);
+</pre>
+</div></div>
+
+<p>Note that the weight field in missing in the resulting JSON:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">
+{<span class="code-quote">"age"</span>:30, <span class="code-quote">"height"</span>:190}
+</pre>
+</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" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">/**
+ * Strategy to exclude {@link ExcludeAge} annotated fields
+ */
+<span class="code-keyword">protected</span> <span class="code-keyword">static</span>
class AgeExclusionStrategy <span class="code-keyword">implements</span> ExclusionStrategy
{
+
+    @Override
+    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
shouldSkipField(FieldAttributes f) {
+        <span class="code-keyword">return</span> f.getAnnotation(ExcludeAge.class)
!= <span class="code-keyword">null</span>;
+    }
+
+    @Override
+    <span class="code-keyword">public</span> <span class="code-object">boolean</span>
shouldSkipClass(<span class="code-object">Class</span>&lt;?&gt; clazz)
{
+        <span class="code-keyword">return</span> <span class="code-keyword">false</span>;
+    }
+}
+</pre>
+</div></div>
+
+<p>The <tt>GsonDataFormat</tt> accepts an <tt>ExclusionStrategy</tt>
in its constructor:</p>
+<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
+<pre class="code-java">GsonDataFormat ageExclusionFormat = <span class="code-keyword">new</span>
GsonDataFormat(TestPojoExclusion.class, <span class="code-keyword">new</span>
AgeExclusionStrategy());
+</pre>
+</div></div>
+<p>The line above will exclude fields annotated with <tt>@ExcludeAge</tt>
during JSON marshalling.</p>
+
 <h3><a shape="rect" name="JSON-DependenciesforXStream"></a>Dependencies
for XStream</h3>
 
 <p>To use JSON in your camel routes you need to add the a dependency on <b>camel-xstream</b>
which implements this data format. </p>



Mime
View raw message