camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r1006514 - in /websites/production/camel/content: cache/main.pageCache xmljson.html
Date Fri, 10 Feb 2017 17:20:10 GMT
Author: buildbot
Date: Fri Feb 10 17:20:10 2017
New Revision: 1006514

Log:
Production update by buildbot for camel

Modified:
    websites/production/camel/content/cache/main.pageCache
    websites/production/camel/content/xmljson.html

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

Modified: websites/production/camel/content/xmljson.html
==============================================================================
--- websites/production/camel/content/xmljson.html (original)
+++ websites/production/camel/content/xmljson.html Fri Feb 10 17:20:10 2017
@@ -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/shBrushJScript.js' type='text/javascript'></script>
   
   <script type="text/javascript">
   SyntaxHighlighter.defaults['toolbar'] = false;
@@ -85,13 +86,13 @@
 	<tbody>
         <tr>
         <td valign="top" width="100%">
-<div class="wiki-content maincontent"><h2 id="XmlJson-XMLJSONDataFormat(camel-xmljson)">XML JSON Data Format (camel-xmljson)</h2><p><strong>Available as of Camel 2.10</strong></p><p>Camel already supports a number of data formats to perform XML and JSON-related conversions, but all of them require a POJO either as an input (for marshalling) or produce a POJO as output (for unmarshalling). This data format provides the capability to convert from XML to JSON and viceversa directly, without stepping through intermediate POJOs.</p><p>This data format leverages the <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/" rel="nofollow">Json-lib</a> library to achieve direct conversion. In this context, XML is considered the high-level format, while JSON is the low-level format. Hence, the marshal/unmarshal semantics are assigned as follows:</p><ul><li>marshalling =&gt; converting from XML to JSON</li><li>unmarshalling =&gt; converting from JSON to XML.</li></ul><h3 i
 d="XmlJson-Options">Options</h3><p>This data format supports the following options. You can set them via all DSLs. The defaults marked with (*) are determined by json-lib, rather than the code of the data format itself. They are reflected here for convenience so that you don't have to dot back and forth with the json-lib docs.</p><div class="confluenceTableSmall"><div class="table-wrap">
- <table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Name</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>encoding</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>UTF-8 (*)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span> <strong>(JSON to XML conversion).</strong> Sets the encoding for the call to <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/apidocs/net/sf/json/xml/XMLSerializer.html#write(net.sf.json.JSON, java.lang.String)" rel="nofollow"><code>XMLSerializer.write()</code></a
 > method, hence it is only used when producing XML. <br clear="none" class="atl-forced-newline"> When producing JSON, the encoding is determined by the input String being processed. If the conversion is performed on an InputStream, json-lib uses the platform's default encoding (e.g. determined by the <code>file.encoding</code> system property).</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>elementName</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>'e' (*)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong> Specifies the name of the XML elements representing each array element. See <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/snippets.html#JSONObject_to_XML_change_node_name
 s" rel="nofollow">json-lib doc</a>.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>arrayName</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>'a' (*)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong> Specifies the name of the top-level XML element. <br clear="none" class="atl-forced-newline"> For example, when converting&#160;<code>[1, 2, 3]</code>, it will be output by default as <code>&lt;a&gt;&lt;e&gt;1&lt;/e&gt;&lt;e&gt;2&lt;/e&gt;&lt;e&gt;3&lt;/e&gt;&lt;/a&gt;</code>. By setting this option or rootName, you can alter the name of element 'a'.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>rootName</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Str
 ing</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>none (*)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong> When converting any JSON construct (object, array, null) to XML (unmarshalling), it specifies the name of the top-level element. <br clear="none" class="atl-forced-newline"> If not set, json-lib will use <code>arrayName</code> or&#160;<code>objectName</code> (default value: 'o', at the current time it is not configurable in this data format). If set to 'root', the JSON string { 'x': 'value1', 'y' : 'value2' } would turn into <code>&lt;root&gt;&lt;x&gt;value1&lt;/x&gt;&lt;y&gt;value2&lt;/y&gt;&lt;/root&gt;</code>, otherwise the 'root' element would be named 'o'.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>namespaceLenient</code></p></td><td colspan="1" rowspan="1" class=
 "confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>false (*)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong> According to the json-lib docs: "Flag to be tolerant to incomplete namespace prefixes." In most cases, json-lib automatically changes this flag at runtime to match the processing.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>namespaceMappings</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>List&lt;NamespacesPerElementMapping&gt;</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>none</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong> Binds namespac
 e prefixes and URIs to specific JSON elements.&#160;<code>NamespacesPerElementMapping</code> is a wrapper around an element name + a Map of prefixes against URIs.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>expandableProperties</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>List&lt;String&gt;</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>none</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong> With expandable properties, JSON array elements are converted to XML as a sequence of repetitive XML elements with the local name equal to the JSON key, for example: { number: 1,2,3 }, normally converted to: <code>&lt;number&gt;&lt;e&gt;1&lt;/e&gt;&lt;e&gt;2&lt;/e&gt;&lt;e&gt;3&lt;/e&gt;&lt;/number&gt;</code> (where e can be modified by setting elementName), would
  instead translate to <code>&lt;number&gt;1&lt;/number&gt;&lt;number&gt;2&lt;/number&gt;&lt;number&gt;3&lt;/number&gt;</code>, if "number" is set as an expandable property</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>typeHints</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>TypeHintsEnum</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>YES</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong> Adds type hints to the resulting XML to aid conversion back to JSON.&#160;See documentation <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/apidocs/net/sf/json/xml/XMLSerializer.html" rel="nofollow">here</a> for an explanation. <code>TypeHintsEnum</code> comprises the following values, which lead to different combinations of the underlying XMLS
 erializer's <code>typeHintsEnabled</code> and <code>typeHintsCompatibility</code> flags:</p>
-     <ul><li><code>TypeHintsEnum.NO</code> =&gt; <code>typeHintsEnabled</code>&#160;= false</li><li><code>TypeHintsEnum.YES</code> =&gt;&#160;&#160;<code>typeHintsEnabled</code> = true,&#160;&#160;<code>typeHintsCompatibility</code> = true</li><li><code>TypeHintsEnum.WITH_PREFIX</code> =&gt;&#160;&#160;<code>typeHintsEnabled</code> = true,&#160;&#160;<code>typeHintsCompatibility</code> = false</li></ul></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>forceTopLevelObject</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>false (*)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span> <strong>(XML to JSON conversion).</strong> Determines whether the resulting JSON will start off with a top-most element whose name matches the XML root element. If disabled, XML str
 ing <code>&lt;a&gt;&lt;x&gt;1&lt;/x&gt;&lt;y&gt;2&lt;/y&gt;&lt;/a&gt;</code> turns into&#160;{ 'x: '1', 'y': '2' }. Otherwise, it turns into&#160;{ 'a': {&#160;'x: '1', 'y': '2' }}.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>skipWhitespace</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>false (*)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span><strong>&#160;(XML to JSON conversion).</strong> Determines whether white spaces between XML elements will be regarded as text values or disregarded.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>trimSpaces</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>false&#160;(*)</p></td><
 td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span><strong>&#160;(XML to JSON conversion).</strong> Determines whether leading and trailing white spaces will be omitted from String values.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>skipNamespaces</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>false&#160;(*)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span><strong>&#160;(XML to JSON conversion).</strong> Signals whether namespaces should be ignored. By default they will be added to the JSON output using @xmlns elements.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>removeNamespacePrefixes</code></p></td><td colspan="1" 
 rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p>false&#160;(*)</p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span><strong>&#160;(XML to JSON conversion).</strong> Removes the namespace prefixes from XML qualified elements, so that the resulting JSON string does not contain them.</p></td></tr></tbody></table>
-</div></div><h3 id="XmlJson-BasicUsagewithJavaDSL">Basic Usage with Java DSL</h3><h4 id="XmlJson-Explicitlyinstantiatingthedataformat">Explicitly instantiating the data format</h4><p>Just instantiate the XmlJsonDataFormat from package org.apache.camel.dataformat.xmljson. Make sure you have installed the <code>camel-xmljson</code> feature (if running on OSGi) or that you've included camel-xmljson-{version}.jar and its transitive dependencies in your classpath. Example initialization with a default configuration:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+<div class="wiki-content maincontent"><h2 id="XmlJson-XMLJSONDataFormat(camel-xmljson)">XML JSON Data Format (camel-xmljson)</h2><p><strong>Available as of Camel 2.10</strong></p><p>Camel already supports a number of data formats to perform XML and JSON-related conversions, but all of them require a POJO either as an input (for marshalling) or produce a POJO as output (for unmarshalling). This data format provides the capability to convert from XML to JSON and viceversa directly, without stepping through intermediate POJOs.</p><p>This data format leverages the <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/" rel="nofollow">Json-lib</a> library to achieve direct conversion. In this context, XML is considered the high-level format, while JSON is the low-level format. Hence, the marshal/unmarshal semantics are assigned as follows:</p><ul><li>marshalling =&gt; converting from XML to JSON</li><li>unmarshalling =&gt; converting from JSON to XML.</li></ul><h3 i
 d="XmlJson-Options">Options</h3><p>This data format supports the following options. You can set them via all DSLs. The defaults marked with&#160;<strong><code>(*)</code></strong> are determined by <strong><code>json-lib</code></strong>, rather than the code of the data format itself. They are reproduced here for convenience to avoid having to consult the <strong><code>json-lib</code></strong> documentation directly.</p><div class="confluenceTableSmall"><div class="table-wrap">
+ <table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"><p>Option</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Type</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Default</p></th><th colspan="1" rowspan="1" class="confluenceTh"><p>Description</p></th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>encoding</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>UTF-8 (*)</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span> <strong>(JSON to XML conversion).</strong></p><p>Sets the encoding for the call to <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/apidocs/net/sf/json/xml/XMLSerializer.html#write(net.sf.json.JSON, java.lang.String)" rel="nofollow"><code>XMLSeriali
 zer.write()</code></a> method, hence it is only used when producing XML. <br clear="none" class="atl-forced-newline"> However, when producing JSON, the encoding is determined by the input String being processed.</p><p>If the conversion is performed on an <strong><code>InputStream</code></strong>,&#160;<strong><code>json-lib</code></strong> uses the platform's default encoding, e.g., determined by the <strong><code>file.encoding</code></strong> system property.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>elementName</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>'e' (*)</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong></p><p>Specifies the name of the XML elements representing each array 
 element.</p><p>See <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/snippets.html#JSONObject_to_XML_change_node_names" rel="nofollow">json-lib doc</a>.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>arrayName</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>'a' (*)</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong></p><p>Specifies the name of the top-level XML element.</p><p>For example, when converting:</p><p><strong><code>[1, 2, 3]</code></strong></p><p>it is, by default, translated as:</p><p><strong><code>&lt;a&gt;&lt;e&gt;1&lt;/e&gt;&lt;e&gt;2&lt;/e&gt;&lt;e&gt;3&lt;/e&gt;&lt;/a&gt;</code></strong></p><p>By setting this option or <strong><code>rootName</code></s
 trong>, you can alter the name of the element <strong><code>a</code></strong>.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>rootName</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>String</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>none (*)</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong></p><p>When converting any JSON construct (<strong><code>object</code>, <code>array</code>, <code>null</code></strong>) to XML (unmarshalling), this option specifies the name of the top-level XML element.</p><p>If not set,&#160;<strong><code>json-lib</code></strong> will use <strong><code>arrayName</code></strong> or&#160;<strong><code>objectName</code></strong> (default value: <strong><code>o</code></strong>, at the current time it is not configurable i
 n this data format).</p><p>If set to <strong><code>root</code></strong>, the JSON string:</p><p><strong><code>{ "x": "value1", "y" : "value2" }</code></strong>&#160;</p><p>is translated as:</p><p><strong><code>&lt;root&gt;&lt;x&gt;value1&lt;/x&gt;&lt;y&gt;value2&lt;/y&gt;&lt;/root&gt;</code></strong></p><p>otherwise the&#160;<strong><code>root</code></strong> element would be named <strong><code>o</code></strong>.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>namespaceLenient</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false (*)</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong></p><p>According to the <strong>json-lib</strong> docs: "<em>Flag to be tolerant to incomplete namespace pref
 ixes.</em>"</p><p>In most cases, j<strong>son-lib</strong> automatically changes this flag at runtime to match the processing.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>namespaceMappings</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>List&lt;NamespacesPerElementMapping&gt;</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>none</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong></p><p>Binds namespace prefixes and URIs to specific JSON elements.&#160;</p><p><strong><code>NamespacesPerElementMapping</code></strong> is a wrapper around an element name + a Map of prefixes against URIs.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>expandableProperties</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><
 code>List&lt;String&gt;</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>none</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong></p><p>With expandable properties, JSON array elements are converted to XML as a sequence of repetitive XML elements with the local name equal to the JSON key.</p><p>For example, the following JSON:&#160;</p><p><strong><code>{ number: 1,2,3 }</code></strong></p><p>is normally translated as:</p><p><strong><code>&lt;number&gt;&lt;e&gt;1&lt;/e&gt;&lt;e&gt;2&lt;/e&gt;&lt;e&gt;3&lt;/e&gt;&lt;/number&gt;</code></strong></p><p>where&#160;<strong><code>e</code></strong> can be modified by setting&#160;<strong><code>elementName</code></strong>.</p><p>However, if&#160;<strong><code>number</code></strong> is set as an expandable property, it's translated as:</p><p><strong><code>&lt;n
 umber&gt;1&lt;/number&gt;&lt;number&gt;2&lt;/number&gt;&lt;number&gt;3&lt;/number&gt;</code></strong></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>typeHints</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>TypeHintsEnum</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>YES</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(0,128,0);"><strong>unmarshalling</strong></span><strong>&#160;(JSON to XML conversion).</strong></p><p>Adds type hints to the resulting XML to aid conversion back to JSON.&#160;See documentation <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/apidocs/net/sf/json/xml/XMLSerializer.html" rel="nofollow">here</a> for an explanation.</p><p><strong><code>TypeHintsEnum</code></strong> comprises the following values, which lead to different combinations of the underlying XMLSerializer's <strong><code>ty
 peHintsEnabled</code></strong> and <strong><code>typeHintsCompatibility</code></strong> flags:</p>
+     <ul><li><code>TypeHintsEnum.NO</code>&#160;<strong><code>=&gt;</code></strong> <code>typeHintsEnabled</code>&#160;=&#160;<code>false</code></li><li><code>TypeHintsEnum.YES</code>&#160;<strong><code>=&gt;</code></strong>&#160; <code>typeHintsEnabled</code> = <code>true</code>,&#160;&#160;<code>typeHintsCompatibility</code> =&#160;<code>true</code></li><li><code>TypeHintsEnum.WITH_PREFIX</code>&#160;<strong><code>=&gt;</code></strong>&#160; <code>typeHintsEnabled</code> = <code>true</code>,&#160;&#160;<code>typeHintsCompatibility</code> = <code>false</code></li></ul></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>forceTopLevelObject</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false (*)</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span
 > <strong>(XML to JSON conversion).</strong></p><p>Determines whether the resulting JSON will start off with a top-most element whose name matches the XML root element.</p><p>If this option is <strong><code>false</code></strong>, the XML string:</p><p><strong><code>&lt;a&gt;&lt;x&gt;1&lt;/x&gt;&lt;y&gt;2&lt;/y&gt;&lt;/a&gt;</code></strong></p><p>is translated as:</p><p><strong><code>{'x: '1', 'y': '2'}</code></strong></p><p>If&#160;<strong><code>true</code></strong>, it's translated as:</p><p><strong><code>{ 'a':&#160; { 'x: '1', 'y': '2' }}</code></strong></p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>skipWhitespace</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false (*)</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span><strong>&#160
 ;(XML to JSON conversion).</strong></p><p>Determines whether white spaces between XML elements will be regarded as text values or disregarded.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>trimSpaces</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false (*)</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span><strong>&#160;(XML to JSON conversion).</strong></p><p>Determines whether leading and trailing white spaces will be omitted from String values.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>skipNamespaces</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false (*)</code></p></td><td colspan="1" rowspan="
 1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span><strong>&#160;(XML to JSON conversion).</strong></p><p>Signals whether namespaces should be ignored. By default they will be added to the JSON output using&#160;<strong><code>@xmlns</code></strong> elements.</p></td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"><p><code>removeNamespacePrefixes</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>Boolean</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><code>false (*)</code></p></td><td colspan="1" rowspan="1" class="confluenceTd"><p><strong>Used when</strong> <span style="color: rgb(51,51,153);"><strong>marshalling</strong></span><strong>&#160;(XML to JSON conversion).</strong></p><p>Removes the namespace prefixes from XML qualified elements, so that the resulting JSON string does not contain them.</p></td></tr></tbody></table>
+</div></div><h3 id="XmlJson-BasicUsageWiththeJavaDSL">Basic Usage With the Java DSL</h3><h4 id="XmlJson-ExplicitlyInstantiatingtheDataFormat">Explicitly Instantiating the DataFormat</h4><p>Just instantiate the&#160;<strong><code>XmlJsonDataFormat</code></strong> from package <strong><code>org.apache.camel.dataformat.xmljson</code></strong>. Make sure you have installed the <strong><code>camel-xmljson</code></strong> feature (if running on OSGi) or that you've included&#160;<strong><code>camel-xmljson-{version}.jar</code></strong> and its transitive dependencies in your classpath.</p><p>Example, initialization with a default configuration:</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[XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
 ]]></script>
-</div></div><p>To tune the behaviour of the data format as per the options above, use the appropriate setters:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>To tune the behavior of the data format as per the options above, use the appropriate setters:</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[XmlJsonDataFormat xmlJsonFormat = new XmlJsonDataFormat();
 xmlJsonFormat.setEncoding(&quot;UTF-8&quot;);
 xmlJsonFormat.setForceTopLevelObject(true);
@@ -101,43 +102,68 @@ xmlJsonFormat.setSkipNamespaces(true);
 xmlJsonFormat.setRemoveNamespacePrefixes(true);
 xmlJsonFormat.setExpandableProperties(Arrays.asList(&quot;d&quot;, &quot;e&quot;));
 ]]></script>
-</div></div><p>Once you've instantiated the data format, the next step is to actually use the it from within the <code>marshal()</code> and <code>unmarshal()</code> DSL elements:</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 XML to JSON
-from(&quot;direct:marshal&quot;).marshal(xmlJsonFormat).to(&quot;mock:json&quot;);
-// from JSON to XML
-from(&quot;direct:unmarshal&quot;).unmarshal(xmlJsonFormat).to(&quot;mock:xml&quot;);
-]]></script>
-</div></div><h4 id="XmlJson-Definingthedataformatin-line">Defining the data format in-line</h4><p>Alternatively, you can define the data format inline by using the <code>xmljson()</code> DSL element.</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 XML to JSON - inline dataformat
-from(&quot;direct:marshalInline&quot;).marshal().xmljson().to(&quot;mock:jsonInline&quot;);
-// from JSON to XML - inline dataformat
-from(&quot;direct:unmarshalInline&quot;).unmarshal().xmljson().to(&quot;mock:xmlInline&quot;);
+</div></div><p>Once the&#160;<strong><code>DataFormat</code></strong> is instantiated, the next step is to use it as a parameter to either of the <strong><code>marshal()</code><code>/</code><code>unmarshal()</code></strong> DSL elements:</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 XML to JSON
+from(&quot;direct:marshal&quot;)
+  .marshal(xmlJsonFormat)
+  .to(&quot;mock:json&quot;);
+
+// From JSON to XML
+from(&quot;direct:unmarshal&quot;)
+  .unmarshal(xmlJsonFormat)
+  .to(&quot;mock:xml&quot;);
+]]></script>
+</div></div><h4 id="XmlJson-DefiningtheDataFormatin-line">Defining the DataFormat in-line</h4><p>Alternatively, you can define the data format inline by using the <strong><code>xmljson()</code></strong> DSL element.</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 XML to JSON - inline dataformat
+from(&quot;direct:marshalInline&quot;)
+  .marshal()
+  .xmljson()
+  .to(&quot;mock:jsonInline&quot;);
+
+// From JSON to XML - inline dataformat
+from(&quot;direct:unmarshalInline&quot;)
+  .unmarshal()
+  .xmljson()
+  .to(&quot;mock:xmlInline&quot;);
 ]]></script>
 </div></div><p>If you wish, you can even pass in a Map&lt;String, String&gt; to the inline methods to provide custom options:</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&lt;String, String&gt; xmlJsonOptions = new HashMap&lt;String, String&gt;();
+
 xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ENCODING, &quot;UTF-8&quot;);
 xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ROOT_NAME, &quot;newRoot&quot;);
 xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.SKIP_NAMESPACES, &quot;true&quot;);
 xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.REMOVE_NAMESPACE_PREFIXES, &quot;true&quot;);
 xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.EXPANDABLE_PROPERTIES, &quot;d e&quot;);
 
-// from XML to JSON - inline dataformat w/ options
-from(&quot;direct:marshalInlineOptions&quot;).marshal().xmljson(xmlJsonOptions).to(&quot;mock:jsonInlineOptions&quot;);
-// form JSON to XML - inline dataformat w/ options
-from(&quot;direct:unmarshalInlineOptions&quot;).unmarshal().xmljson(xmlJsonOptions).to(&quot;mock:xmlInlineOptions&quot;);
+// From XML to JSON - inline dataformat w/options
+from(&quot;direct:marshalInlineOptions&quot;)
+  .marshal()
+  .xmljson(xmlJsonOptions)
+  .to(&quot;mock:jsonInlineOptions&quot;);
+
+// Fromm JSON to XML - inline dataformat w/options
+from(&quot;direct:unmarshalInlineOptions&quot;)
+  .unmarshal()
+  .xmljson(xmlJsonOptions)
+  .to(&quot;mock:xmlInlineOptions&quot;);
 ]]></script>
-</div></div><h3 id="XmlJson-BasicusagewithSpringorBlueprintDSL">Basic usage with Spring or Blueprint DSL</h3><p>Within the <code>&lt;dataFormats&gt;</code> block, simply configure an <code>xmljson</code> element with unique IDs:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><h3 id="XmlJson-BasicUsagewithSpringorBlueprintDSL">Basic Usage with Spring or Blueprint DSL</h3><p>Within the <strong><code>&lt;dataFormats&gt;</code></strong> block, simply configure an <strong><code>xmljson</code></strong> element with unique IDs:</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;xmljson id=&quot;xmljson&quot;/&gt;
-    &lt;xmljson id=&quot;xmljsonWithOptions&quot; forceTopLevelObject=&quot;true&quot; trimSpaces=&quot;true&quot; rootName=&quot;newRoot&quot; skipNamespaces=&quot;true&quot; 
-             removeNamespacePrefixes=&quot;true&quot; expandableProperties=&quot;d e&quot;/&gt;
+    &lt;xmljson id=&quot;xmljsonWithOptions&quot; 
+             forceTopLevelObject=&quot;true&quot; 
+             trimSpaces=&quot;true&quot; 
+             rootName=&quot;newRoot&quot; 
+             skipNamespaces=&quot;true&quot; 
+             removeNamespacePrefixes=&quot;true&quot; 
+             expandableProperties=&quot;d e&quot;/&gt;
 &lt;/dataFormats&gt;
 ]]></script>
-</div></div><p>Then you simply refer to the data format object within your <code>&lt;marshal /&gt;</code> and {&lt;unmarshal /&gt;}} DSLs:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>Then you simply refer to the data format object within your <strong><code>&lt;marshal/&gt;</code></strong> and&#160;<strong><code>&lt;unmarshal/&gt;</code></strong> DSLs:</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:marshal&quot;/&gt;
     &lt;marshal ref=&quot;xmljson&quot;/&gt;
-    &lt;to uri=&quot;mock:json&quot; /&gt;
+    &lt;to uri=&quot;mock:json&quot;/&gt;
 &lt;/route&gt;
 
 &lt;route&gt;
@@ -146,22 +172,20 @@ from(&quot;direct:unmarshalInlineOptions
     &lt;to uri=&quot;mock:xmlWithOptions&quot;/&gt;
 &lt;/route&gt;
 ]]></script>
-</div></div><p>Enabling XML DSL autocompletion for this component is easy: just refer to the appropriate <a shape="rect" class="external-link" href="http://camel.apache.org/xml-reference.html">Schema locations</a>, depending on whether you're using <a shape="rect" class="external-link" href="http://camel.apache.org/schema/spring/">Spring</a> or <a shape="rect" class="external-link" href="http://camel.apache.org/schema/blueprint/">Blueprint</a> DSL. Remember that this data format is available from Camel 2.10 onwards, so only schemas from that version onwards will include these new XML elements and attributes.</p><p>The syntax with <a shape="rect" href="using-osgi-blueprint-with-camel.html">Blueprint</a> is identical to that of the Spring DSL. Just ensure the correct namespaces and schemaLocations are in use.</p><h3 id="XmlJson-Namespacemappings">Namespace mappings</h3><p>XML has namespaces to fully qualify elements and attributes; JSON doesn't. You need to take this into account when
  performing XML-JSON conversions.</p><p>To bridge the gap, <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/" rel="nofollow">Json-lib</a> has an option to bind namespace declarations in the form of prefixes and namespace URIs to XML output elements while unmarshalling (i.e. converting from JSON to XML). For example, provided the following 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[{ &#39;pref1:a&#39;: &#39;value1&#39;, &#39;pref2:b&#39;: &#39;value2 }
+</div></div><p>Enabling XML DSL autocompletion for this component is easy: just refer to the appropriate <a shape="rect" class="external-link" href="http://camel.apache.org/xml-reference.html">Schema locations</a>, depending on whether you're using <a shape="rect" class="external-link" href="http://camel.apache.org/schema/spring/">Spring</a> or <a shape="rect" class="external-link" href="http://camel.apache.org/schema/blueprint/">Blueprint</a> DSL. Remember that this data format is available from Camel 2.10. Therefore only schemas from that version or later will include these new XML elements and attributes.</p><p>The syntax with <a shape="rect" href="using-osgi-blueprint-with-camel.html">Blueprint</a> is identical to that of the Spring DSL. Just ensure the correct namespaces and&#160;<strong><code>schemaLocations</code></strong> are in use.</p><h3 id="XmlJson-NamespaceMappings">Namespace Mappings</h3><p>XML has namespaces to fully qualify elements and attributes; JSON doesn't. You 
 need to take this into account when performing XML-JSON conversions.</p><p>To bridge the gap, <a shape="rect" class="external-link" href="http://json-lib.sourceforge.net/" rel="nofollow">Json-lib</a> has an option to bind namespace declarations in the form of prefixes and namespace URIs to XML output elements while unmarshalling, e.g., converting from JSON to XML.</p><p>For example, provided the following 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[{ &quot;pref1:a&quot;: &quot;value1&quot;, &quot;pref2:b&quot;: &quot;value2&quot; }
 ]]></script>
-</div></div><p>you can ask Json-lib to output namespace declarations on elements "pref1:a" and "pref2:b" to bind the prefixes "pref1" and "pref2" to specific namespace URIs.</p><p>To use this feature, simply create <code>XmlJsonDataFormat.NamespacesPerElementMapping</code> objects and add them to the <code>namespaceMappings</code> option (which is a <code>List</code>).</p><p>The <code>XmlJsonDataFormat.NamespacesPerElementMapping</code> holds an element name and a Map of [prefix =&gt; namespace URI]. To facilitate mapping multiple prefixes and namespace URIs, the <code>NamespacesPerElementMapping(String element, String pipeSeparatedMappings)</code> constructor takes a String-based pipe-separated sequence of [prefix, namespaceURI] pairs in the following way: <code>|ns2|http://camel.apache.org/personalData|ns3|http://camel.apache.org/personalData2|</code>.</p><p>In order to define a default namespace, just leave the corresponding key field empty: <code>|ns1|http://camel.apache.org/tes
 t1||http://camel.apache.org/default|</code>.</p><p>Binding namespace declarations to an element name = empty string will attach those namespaces to the root element.</p><p>The full code would look like that:</p><div class="code panel pdl" style="border-width: 1px;"><div class="codeContent panelContent pdl">
+</div></div><p>you can ask&#160;<strong><code>json-lib</code></strong> to output namespace declarations on elements&#160;<strong><code>pref1:a</code></strong> and&#160;<strong><code>pref2:b</code></strong> to bind the prefixes&#160;<strong><code>pref1</code></strong> and&#160;<strong><code>pref2</code></strong> to specific namespace URIs.</p><p>To use this feature, simply create <strong><code>XmlJsonDataFormat.NamespacesPerElementMapping</code></strong> objects and add them to the <strong><code>namespaceMappings</code></strong> option (which is a <strong><code>List</code></strong>).</p><p>The <strong><code>XmlJsonDataFormat.NamespacesPerElementMapping</code></strong> holds an element name and a Map of <strong><code>[prefix =&gt; namespace URI]</code></strong>. To facilitate mapping multiple prefixes and namespace URIs, the <strong><code>NamespacesPerElementMapping(String element, String pipeSeparatedMappings)</code></strong> constructor takes a String-based pipe-separated sequence o
 f&#160;<strong><code>[prefix, namespaceURI]</code></strong> pairs in the following way: <strong><code>|ns2|http://camel.apache.org/personalData|ns3|http://camel.apache.org/personalData2|</code></strong>.</p><p>In order to define a default namespace, just leave the corresponding key field empty: <strong><code>|ns1|http://camel.apache.org/test1||http://camel.apache.org/default|</code>.</strong></p><p>Binding namespace declarations to an element name = empty string will attach those namespaces to the root element.</p><p>The code for this is:</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[XmlJsonDataFormat namespacesFormat = new XmlJsonDataFormat();
 List&lt;XmlJsonDataFormat.NamespacesPerElementMapping&gt; namespaces = new ArrayList&lt;XmlJsonDataFormat.NamespacesPerElementMapping&gt;();
-namespaces.add(new XmlJsonDataFormat.
-                       NamespacesPerElementMapping(&quot;&quot;, &quot;|ns1|http://camel.apache.org/test1||http://camel.apache.org/default|&quot;));
-namespaces.add(new XmlJsonDataFormat.
-                       NamespacesPerElementMapping(&quot;surname&quot;, &quot;|ns2|http://camel.apache.org/personalData|&quot; + 
-                           &quot;ns3|http://camel.apache.org/personalData2|&quot;));
+
+namespaces.add(new XmlJsonDataFormat.NamespacesPerElementMapping(&quot;&quot;, &quot;|ns1|http://camel.apache.org/test1||http://camel.apache.org/default|&quot;));
+namespaces.add(new XmlJsonDataFormat.NamespacesPerElementMapping(&quot;surname&quot;, &quot;|ns2|http://camel.apache.org/personalData|ns3|http://camel.apache.org/personalData2|&quot;));
 namespacesFormat.setNamespaceMappings(namespaces);
 namespacesFormat.setRootElement(&quot;person&quot;);
 ]]></script>
 </div></div><p>And you can achieve the same in Spring DSL.</p><h4 id="XmlJson-Example">Example</h4><p>Using the namespace bindings in the Java snippet above on the following 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[{ &quot;name&quot;: &quot;Raul&quot;, &quot;surname&quot;: &quot;Kripalani&quot;, &quot;f&quot;: true, &quot;g&quot;: null}]]></script>
+<script class="brush: js; gutter: false; theme: Default" type="syntaxhighlighter"><![CDATA[{ &quot;name&quot;: &quot;Raul&quot;, &quot;surname&quot;: &quot;Kripalani&quot;, &quot;f&quot;: true, &quot;g&quot;: null}]]></script>
 </div></div><p>&#160;</p><p>Would yield the following XML:</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;person xmlns=&quot;http://camel.apache.org/default&quot; xmlns:ns1=&quot;http://camel.apache.org/test1&quot;&gt;
     &lt;f&gt;true&lt;/f&gt;
@@ -175,7 +199,7 @@ namespacesFormat.setRootElement(&quot;pe
   &lt;groupId&gt;org.apache.camel&lt;/groupId&gt;
   &lt;artifactId&gt;camel-xmljson&lt;/artifactId&gt;
   &lt;version&gt;x.x.x&lt;/version&gt;
-  &lt;!-- Use the same version as camel-core, but remember that this component is only available from 2.10 onwards --&gt;
+  &lt;!-- Use the same version as camel-core, but remember that this component is only available from Camel 2.10 --&gt;
 &lt;/dependency&gt;
 
 &lt;!-- And also XOM must be included. XOM cannot be included by default due to an incompatible



Mime
View raw message