|
Author: buildbot
Date: Mon May 21 18:20:22 2012 New Revision: 818581 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/data-format-list.html websites/production/camel/content/data-format.html websites/production/camel/content/json.html websites/production/camel/content/xmljson.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 May 21 18:20:22 2012 @@ -104,6 +104,11 @@ </li></ul> +<ul><li>Direct JSON / XML marshalling + <ul><li><a shape="rect" href="xmljson.html" title="XmlJson">XmlJson</a></li></ul> + </li></ul> + + <ul><li>Flat data structure marshalling <ul><li><a shape="rect" href="beanio.html" title="BeanIO">BeanIO</a></li><li><a shape="rect" href="bindy.html" title="Bindy">Bindy</a></li><li><a shape="rect" href="csv.html" title="CSV">CSV</a></li><li><a shape="rect" href="edi.html" title="EDI">EDI</a></li><li><a shape="rect" href="flatpack-dataformat.html" title="Flatpack DataFormat">Flatpack DataFormat</a></li></ul> </li></ul> @@ -870,15 +875,16 @@ from(<span class="code-quote">"seda:peop </div></div> <h2><a shape="rect" name="BookDataFormatAppendix-JSON"></a>JSON</h2> -<p>JSON is a <a shape="rect" href="data-format.html" title="Data Format">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>JSON is a <a shape="rect" href="data-format.html" title="Data Format">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>Camel supports the following libraries:<br clear="none"> -Camel provides integration with three popular JSON libraries:</p> +<p>For JSON to object marshalling, Camel provides integration with three popular JSON libraries:</p> <ul class="alternate" type="square"><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="http://xircles.codehaus.org/projects/jackson" rel="nofollow">Jackson library</a></li><li><b>Camel 2.10:</b> The <a shape="rect" class="external-link" href="http://code.google.com/p/google-gson/" rel="nofollow">GSon library</a></li></ul> <p>By default Camel uses the XStream library. </p> +<div class="panelMacro"><table class="tipMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/check.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1"><b>Direct, bi-directional JSON <=> XML conversions</b><br clear="none">As of Camel 2.10, Camel supports direct, bi-directional JSON <=> XML conversions via the <a shape="rect" href="xmljson.html" title="XmlJson">camel-xmljson</a> data format, which is documented separately.</td></tr></table></div> + <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"> 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 May 21 18:20:22 2012 @@ -10941,6 +10941,11 @@ from(<span class="code-quote">"direct:st </li></ul> +<ul><li>Direct JSON / XML marshalling + <ul><li><a shape="rect" href="xmljson.html" title="XmlJson">XmlJson</a></li></ul> + </li></ul> + + <ul><li>Flat data structure marshalling <ul><li><a shape="rect" href="beanio.html" title="BeanIO">BeanIO</a></li><li><a shape="rect" href="bindy.html" title="Bindy">Bindy</a></li><li><a shape="rect" href="csv.html" title="CSV">CSV</a></li><li><a shape="rect" href="edi.html" title="EDI">EDI</a></li><li><a shape="rect" href="flatpack-dataformat.html" title="Flatpack DataFormat">Flatpack DataFormat</a></li></ul> </li></ul> @@ -11707,15 +11712,16 @@ from(<span class="code-quote">"seda:peop </div></div> <h2><a shape="rect" name="BookInOnePage-JSON"></a>JSON</h2> -<p>JSON is a <a shape="rect" href="data-format.html" title="Data Format">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>JSON is a <a shape="rect" href="data-format.html" title="Data Format">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>Camel supports the following libraries:<br clear="none"> -Camel provides integration with three popular JSON libraries:</p> +<p>For JSON to object marshalling, Camel provides integration with three popular JSON libraries:</p> <ul class="alternate" type="square"><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="http://xircles.codehaus.org/projects/jackson" rel="nofollow">Jackson library</a></li><li><b>Camel 2.10:</b> The <a shape="rect" class="external-link" href="http://code.google.com/p/google-gson/" rel="nofollow">GSon library</a></li></ul> <p>By default Camel uses the XStream library. </p> +<div class="panelMacro"><table class="tipMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/check.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1"><b>Direct, bi-directional JSON <=> XML conversions</b><br clear="none">As of Camel 2.10, Camel supports direct, bi-directional JSON <=> XML conversions via the <a shape="rect" href="xmljson.html" title="XmlJson">camel-xmljson</a> data format, which is documented separately.</td></tr></table></div> + <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"> Modified: websites/production/camel/content/cache/main.pageCache ============================================================================== Binary files - no diff available. Modified: websites/production/camel/content/data-format-list.html ============================================================================== --- websites/production/camel/content/data-format-list.html (original) +++ websites/production/camel/content/data-format-list.html Mon May 21 18:20:22 2012 @@ -95,6 +95,11 @@ </li></ul> +<ul><li>Direct JSON / XML marshalling + <ul><li><a shape="rect" href="xmljson.html" title="XmlJson">XmlJson</a></li></ul> + </li></ul> + + <ul><li>Flat data structure marshalling <ul><li><a shape="rect" href="beanio.html" title="BeanIO">BeanIO</a></li><li><a shape="rect" href="bindy.html" title="Bindy">Bindy</a></li><li><a shape="rect" href="csv.html" title="CSV">CSV</a></li><li><a shape="rect" href="edi.html" title="EDI">EDI</a></li><li><a shape="rect" href="flatpack-dataformat.html" title="Flatpack DataFormat">Flatpack DataFormat</a></li></ul> </li></ul> Modified: websites/production/camel/content/data-format.html ============================================================================== --- websites/production/camel/content/data-format.html (original) +++ websites/production/camel/content/data-format.html Mon May 21 18:20:22 2012 @@ -101,6 +101,11 @@ </li></ul> +<ul><li>Direct JSON / XML marshalling + <ul><li><a shape="rect" href="xmljson.html" title="XmlJson">XmlJson</a></li></ul> + </li></ul> + + <ul><li>Flat data structure marshalling <ul><li><a shape="rect" href="beanio.html" title="BeanIO">BeanIO</a></li><li><a shape="rect" href="bindy.html" title="Bindy">Bindy</a></li><li><a shape="rect" href="csv.html" title="CSV">CSV</a></li><li><a shape="rect" href="edi.html" title="EDI">EDI</a></li><li><a shape="rect" href="flatpack-dataformat.html" title="Flatpack DataFormat">Flatpack DataFormat</a></li></ul> </li></ul> Modified: websites/production/camel/content/json.html ============================================================================== --- websites/production/camel/content/json.html (original) +++ websites/production/camel/content/json.html Mon May 21 18:20:22 2012 @@ -76,15 +76,16 @@ <tr> <td valign="top" width="100%"> <div class="wiki-content maincontent"><h2><a shape="rect" name="JSON-JSON"></a>JSON</h2> -<p>JSON is a <a shape="rect" href="data-format.html" title="Data Format">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>JSON is a <a shape="rect" href="data-format.html" title="Data Format">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>Camel supports the following libraries:<br clear="none"> -Camel provides integration with three popular JSON libraries:</p> +<p>For JSON to object marshalling, Camel provides integration with three popular JSON libraries:</p> <ul class="alternate" type="square"><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="http://xircles.codehaus.org/projects/jackson" rel="nofollow">Jackson library</a></li><li><b>Camel 2.10:</b> The <a shape="rect" class="external-link" href="http://code.google.com/p/google-gson/" rel="nofollow">GSon library</a></li></ul> <p>By default Camel uses the XStream library. </p> +<div class="panelMacro"><table class="tipMacro"><colgroup span="1"><col span="1" width="24"><col span="1"></colgroup><tr><td colspan="1" rowspan="1" valign="top"><img align="middle" src="https://cwiki.apache.org/confluence/images/icons/emoticons/check.gif" width="16" height="16" alt="" border="0"></td><td colspan="1" rowspan="1"><b>Direct, bi-directional JSON <=> XML conversions</b><br clear="none">As of Camel 2.10, Camel supports direct, bi-directional JSON <=> XML conversions via the <a shape="rect" href="xmljson.html" title="XmlJson">camel-xmljson</a> data format, which is documented separately.</td></tr></table></div> + <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"> Modified: websites/production/camel/content/xmljson.html ============================================================================== --- websites/production/camel/content/xmljson.html (original) +++ websites/production/camel/content/xmljson.html Mon May 21 18:20:22 2012 @@ -81,36 +81,39 @@ <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, marshalling means <font color="#ff0000">xxx</font> and unmarshalling means <font color="#ff0000">xxx</font>.</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 => converting from XML to JSON</li><li>unmarshalling => converting from JSON to XML.</li></ul> + <h3><a shape="rect" name="XmlJson-Options"></a>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"> Name </th><th colspan="1" rowspan="1" class="confluenceTh"> Type </th><th colspan="1" rowspan="1" class="confluenceTh"> Default </th><th colspan="1" rowspan="1" class="confluenceTh"> Description </th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>encoding</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>String</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> UTF-8 (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when unmarshalling (JSON to XML conversion).</b> 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"><tt>XMLSerializer.write()</tt></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 <tt>file.encoding</tt> system property). </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>elementName</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>String</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> 'e' (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when unmarshalling (JSON to XML conversion).</b> 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_names" rel="nofollow">json-lib doc</a>. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>arrayName</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>String</tt> </td><td colspan="1" r owspan="1" class="confluenceTd"> 'a' (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when unmarshalling (JSON to XML conversion).</b> Specifies the name of the top-level XML element. <br clear="none" class="atl-forced-newline"> -For example, when converting <tt>[1, 2, 3]</tt>, it will be output by default as <tt><a><e>1</e><e>2</e><e>3</e></a></tt>. By setting this option or rootName, you can alter the name of element 'a'. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>rootName</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>String</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> none (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when unmarshalling (JSON to XML conversion).</b> 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 <tt>arrayName</tt> or <tt>objectName</tt> (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 <tt><root><x>value1</x><y>value2</y></root></tt>, otherwise the 'root' element would be named 'o'. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>forceTopLevelObject</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when marshalling (XML to JSON conversion).</b> Determines whether the resulting JSON will start off with a top-most element whose name matches the XML root element. If disabled, XML string <tt><a><x>1</x><y>2</y></a></tt> turns into { 'x: '1', 'y': '2' }. Otherwise, it tur ns into { 'a': { 'x: '1', 'y': '2' }}. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>namespaceLenient</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when unmarshalling (JSON to XML conversion).</b> 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. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>namespaceMappings</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>List<NamespacesPerElementMapping></tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> none </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when unmarshalling (JSON to XML conversion).</b> Binds namespace prefixes and URIs to specific JSON ele ments. <tt>NamespacesPerElementMapping</tt> is a wrapper around an element name + a Map of prefixes against URIs. <br clear="none" class="atl-forced-newline"> </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>skipWhitespace</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when marshalling (XML to JSON conversion).</b> Determines whether white spaces between XML elements will be regarded as text values or disregarded. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>trimSpaces</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when marshalling (XML to JSON conversion).</b> Determines whether leading and trailing white spaces will be omitted from String values. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>skipNamespaces</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when marshalling (XML to JSON conversion).</b> Signals whether namespaces should be ignored. By default they will be added to the JSON output using @xmlns elements. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>removeNamespacePrefixes</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when marshalling (XML to JSON conversion).</b> Removes the namespace prefixes from XML qualified elements, so that the resulting JSON string does not contain them. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>expandableProperties</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>List<String></tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> none </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when unmarshalling (JSON to XML conversion).</b> 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: <tt><number><e>1</e><e>2</e><e>3</e></number></tt> (where e can be modified by setting elementName), would instead translate to <tt><number>1</number><number>2</number><number>3</number></tt>, if "number" is set as an expandable property </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>typeHints</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> < tt>TypeHintsEnum</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> YES </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when unmarshalling (JSON to XML conversion).</b> Adds type hints to the resulting XML to aid conversion back to JSON. 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. <tt>TypeHintsEnum</tt> comprises the following values, which lead to different combinations of the underlying XMLSerializer's <tt>typeHintsEnabled</tt> and <tt>typeHintsCompatibility</tt> flags: <br clear="none" class="atl-forced-newline"> +<table class="confluenceTable"><tbody><tr><th colspan="1" rowspan="1" class="confluenceTh"> Name </th><th colspan="1" rowspan="1" class="confluenceTh"> Type </th><th colspan="1" rowspan="1" class="confluenceTh"> Default </th><th colspan="1" rowspan="1" class="confluenceTh"> Description </th></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>encoding</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>String</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> UTF-8 (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#008000"><b>unmarshalling</b></font> <b>(JSON to XML conversion).</b> 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"><tt>XMLSerializer.write()</tt></a> method, hence it is only used when producing XML. <br clear="none" class="atl-force d-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 <tt>file.encoding</tt> system property). </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>elementName</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>String</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> 'e' (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#008000"><b>unmarshalling</b></font><b> (JSON to XML conversion).</b> 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_names" rel="nofollow">json-lib doc</a>. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>arrayName</tt> </td><td colspan="1" rowspan="1" class="confl uenceTd"> <tt>String</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> 'a' (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#008000"><b>unmarshalling</b></font><b> (JSON to XML conversion).</b> Specifies the name of the top-level XML element. <br clear="none" class="atl-forced-newline"> +For example, when converting <tt>[1, 2, 3]</tt>, it will be output by default as <tt><a><e>1</e><e>2</e><e>3</e></a></tt>. By setting this option or rootName, you can alter the name of element 'a'. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>rootName</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>String</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> none (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#008000"><b>unmarshalling</b></font><b> (JSON to XML conversion).</b> 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 <tt>arrayName</tt> or <tt>objectName</tt> (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 <tt><root><x>value1</x><y>value2</y></root></tt>, otherwise the 'root' element would be named 'o'. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>namespaceLenient</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#008000"><b>unmarshalling</b></font><b> (JSON to XML conversion).</b> 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. </td></tr><tr><td colspan="1" rowspan="1 " class="confluenceTd"> <tt>namespaceMappings</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>List<NamespacesPerElementMapping></tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> none </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#008000"><b>unmarshalling</b></font><b> (JSON to XML conversion).</b> Binds namespace prefixes and URIs to specific JSON elements. <tt>NamespacesPerElementMapping</tt> is a wrapper around an element name + a Map of prefixes against URIs. <br clear="none" class="atl-forced-newline"> </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>expandableProperties</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>List<String></tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> none </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#008000"><b>unmarshalling</b></font><b> (JSON to XML conversion).</b> 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: <tt><number><e>1</e><e>2</e><e>3</e></number></tt> (where e can be modified by setting elementName), would instead translate to <tt><number>1</number><number>2</number><number>3</number></tt>, if "number" is set as an expandable property </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>typeHints</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>TypeHintsEnum</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> YES </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#008000"><b>unmarshalling</b></font><b> (JSON to XML conversion).</b> Adds type hints to the resulting XML to aid conversion back to JSON. 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. <tt>TypeHintsEnum</tt> comprises the following values, which lead to different combinations of the underlying XMLSerializer's <tt>typeHintsEnabled</tt> and <tt>typeHintsCompatibility</tt> flags: <br clear="none" class="atl-forced-newline"> <ul><li><tt>TypeHintsEnum.NO</tt> => <tt>typeHintsEnabled</tt> = false</li><li><tt>TypeHintsEnum.YES</tt> =>  <tt>typeHintsEnabled</tt> = true,  <tt>typeHintsCompatibility</tt> = true</li><li><tt>TypeHintsEnum.WITH_PREFIX</tt> =>  <tt>typeHintsEnabled</tt> = true,  <tt>typeHintsCompatibility</tt> = false</li></ul> -</td></tr></tbody></table> +</td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>forceTopLevelObject</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#333399"><b>marshalling</b></font> <b>(XML to JSON conversion).</b> Determines whether the resulting JSON will start off with a top-most element whose name matches the XML root element. If disabled, XML string <tt><a><x>1</x><y>2</y></a></tt> turns into { 'x: '1', 'y': '2' }. Otherwise, it turns into { 'a': { 'x: '1', 'y': '2' }}. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>skipWhitespace</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used wh en</b> <font color="#333399"><b>marshalling</b></font><b> (XML to JSON conversion).</b> Determines whether white spaces between XML elements will be regarded as text values or disregarded. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>trimSpaces</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#333399"><b>marshalling</b></font><b> (XML to JSON conversion).</b> Determines whether leading and trailing white spaces will be omitted from String values. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>skipNamespaces</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#333399 "><b>marshalling</b></font><b> (XML to JSON conversion).</b> Signals whether namespaces should be ignored. By default they will be added to the JSON output using @xmlns elements. </td></tr><tr><td colspan="1" rowspan="1" class="confluenceTd"> <tt>removeNamespacePrefixes</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> <tt>Boolean</tt> </td><td colspan="1" rowspan="1" class="confluenceTd"> false (*) </td><td colspan="1" rowspan="1" class="confluenceTd"> <b>Used when</b> <font color="#333399"><b>marshalling</b></font><b> (XML to JSON conversion).</b> Removes the namespace prefixes from XML qualified elements, so that the resulting JSON string does not contain them. </td></tr></tbody></table> </div> </div> <h3><a shape="rect" name="XmlJson-BasicUsagewithJavaDSL"></a>Basic Usage with Java DSL</h3> -<p>With a default configuration:</p> +<h4><a shape="rect" name="XmlJson-Explicitlyinstantiatingthedataformat"></a>Explicitly instantiating the data format</h4> + +<p>Just instantiate the XmlJsonDataFormat from package org.apache.camel.dataformat.xmljson. Make sure you have installed the <tt>camel-xmljson</tt> 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" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -XmlJsonDataFormat xmlJsonFormat = <span class="code-keyword">new</span> XmlJsonDataFormat(); +<pre class="code-java">XmlJsonDataFormat xmlJsonFormat = <span class="code-keyword">new</span> XmlJsonDataFormat(); </pre> </div></div> -<p>Or with a more detailed configuration, as per the options above:</p> +<p>To tune the behaviour of the data format as per the options above, use the appropriate setters:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -XmlJsonDataFormat xmlJsonFormat = <span class="code-keyword">new</span> XmlJsonDataFormat(); +<pre class="code-java">XmlJsonDataFormat xmlJsonFormat = <span class="code-keyword">new</span> XmlJsonDataFormat(); xmlJsonFormat.setEncoding(<span class="code-quote">"UTF-8"</span>); xmlJsonFormat.setForceTopLevelObject(<span class="code-keyword">true</span>); xmlJsonFormat.setTrimSpaces(<span class="code-keyword">true</span>); @@ -121,22 +124,22 @@ xmlJsonFormat.setExpandableProperties(Ar </pre> </div></div> -<p>The next step is to actually use the data format within the <tt>marshal()</tt> and <tt>unmarshal()</tt> DSL elements:</p> +<p>Once you've instantiated the data format, the next step is to actually use the it from within the <tt>marshal()</tt> and <tt>unmarshal()</tt> DSL elements:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -<span class="code-comment">// from XML to JSON +<pre class="code-java"><span class="code-comment">// from XML to JSON </span>from(<span class="code-quote">"direct:marshal"</span>).marshal(xmlJsonFormat).to(<span class="code-quote">"mock:json"</span>); <span class="code-comment">// from JSON to XML </span>from(<span class="code-quote">"direct:unmarshal"</span>).unmarshal(xmlJsonFormat).to(<span class="code-quote">"mock:xml"</span>); </pre> </div></div> -<p>Alternatively, you can define the data format inline:</p> +<h4><a shape="rect" name="XmlJson-Definingthedataformatinline"></a>Defining the data format in-line</h4> + +<p>Alternatively, you can define the data format inline by using the <tt>xmljson()</tt> DSL element.</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -<span class="code-comment">// from XML to JSON - inline dataformat +<pre class="code-java"><span class="code-comment">// from XML to JSON - inline dataformat </span>from(<span class="code-quote">"direct:marshalInline"</span>).marshal().xmljson().to(<span class="code-quote">"mock:jsonInline"</span>); <span class="code-comment">// from JSON to XML - inline dataformat </span>from(<span class="code-quote">"direct:unmarshalInline"</span>).unmarshal().xmljson().to(<span class="code-quote">"mock:xmlInline"</span>); @@ -146,8 +149,7 @@ xmlJsonFormat.setExpandableProperties(Ar <p>If you wish, you can even pass in a Map<String, String> to the inline methods to provide custom options:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-java"> -Map<<span class="code-object">String</span>, <span class="code-object">String</span>> xmlJsonOptions = <span class="code-keyword">new</span> HashMap<<span class="code-object">String</span>, <span class="code-object">String</span>>(); +<pre class="code-java">Map<<span class="code-object">String</span>, <span class="code-object">String</span>> xmlJsonOptions = <span class="code-keyword">new</span> HashMap<<span class="code-object">String</span>, <span class="code-object">String</span>>(); xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ENCODING, <span class="code-quote">"UTF-8"</span>); xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.ROOT_NAME, <span class="code-quote">"newRoot"</span>); xmlJsonOptions.put(org.apache.camel.model.dataformat.XmlJsonDataFormat.SKIP_NAMESPACES, <span class="code-quote">"<span class="code-keyword">true</span>"</span>); @@ -166,8 +168,7 @@ xmlJsonOptions.put(org.apache.camel.mode <p>Within the <tt><dataFormats></tt> block, simply configure an <tt>xmljson</tt> element with unique IDs:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-xml"> -<span class="code-tag"><dataFormats></span> +<pre class="code-xml"><span class="code-tag"><dataFormats></span> <span class="code-tag"><xmljson id=<span class="code-quote">"xmljson"</span>/></span> <span class="code-tag"><xmljson id=<span class="code-quote">"xmljsonWithOptions"</span> forceTopLevelObject=<span class="code-quote">"true"</span> trimSpaces=<span class="code-quote">"true"</span> rootName=<span class="code-quote">"newRoot"</span> skipNamespaces=<span class="code-quote">"true"</span> removeNamespacePrefixes=<span class="code-quote">"true"</span> expandableProperties=<span class="code-quote">"d e"</span>/></span> <span class="code-tag"></dataFormats></span> @@ -177,8 +178,7 @@ xmlJsonOptions.put(org.apache.camel.mode <p>Then you simply refer to the data format object within your <tt><marshal /></tt> and {<unmarshal />}} DSLs:</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-xml"> -<span class="code-tag"><route></span> +<pre class="code-xml"><span class="code-tag"><route></span> <span class="code-tag"><from uri=<span class="code-quote">"direct:marshal"</span>/></span> <span class="code-tag"><marshal ref=<span class="code-quote">"xmljson"</span>/></span> <span class="code-tag"><to uri=<span class="code-quote">"mock:json"</span> /></span> @@ -198,14 +198,64 @@ xmlJsonOptions.put(org.apache.camel.mode <h3><a shape="rect" name="XmlJson-Namespacemappings"></a>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 attempt 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, if you have the JSON string { 'pref1:a': 'value1', 'pref2:b': 'value2 }, 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 <tt>XmlJsonDataFormat.NamespacesPerElementMapping</tt> objects, one per element to which you need to bind namespace declarations, and add them to the <tt>namespaceMappings</tt> option (which is a <tt>List</tt>).<br clear="none"> +The <tt>XmlJsonDataFormat.NamespacesPerElementMapping</tt> holds an element name and a Map of [prefix => namespace URI]. To facilitate mapping multiple prefixes and namespace URIs, the <tt>NamespacesPerElementMapping(String element, String pipeSeparatedMappings)</tt> constructor takes a String-based pipe-separated sequence of <span class="error">[prefix, namespaceURI]</span> pairs in the following way: <tt>|ns2|http://camel.apache.org/personalData|ns3|http://camel.apache.org/personalData2|</tt>.</p> + +<p>In order to define a default namespace, just leave the corresponding key field empty: <tt>|ns1|http://camel.apache.org/test1||http://camel.apache.org/default|</tt>.<br clear="none"> +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" style="border-width: 1px;"><div class="codeContent panelContent"> +<pre class="code-java">XmlJsonDataFormat namespacesFormat = <span class="code-keyword">new</span> XmlJsonDataFormat(); +List<XmlJsonDataFormat.NamespacesPerElementMapping> namespaces = <span class="code-keyword">new</span> ArrayList<XmlJsonDataFormat.NamespacesPerElementMapping>(); +namespaces.add(<span class="code-keyword">new</span> XmlJsonDataFormat.NamespacesPerElementMapping(<span class="code-quote">"", "</span>|ns1|http:<span class="code-comment">//camel.apache.org/test1||http://camel.apache.org/<span class="code-keyword">default</span>|")); +</span>namespaces.add(<span class="code-keyword">new</span> XmlJsonDataFormat.NamespacesPerElementMapping(<span class="code-quote">"surname"</span>, <span class="code-quote">"|ns2|http:<span class="code-comment">//camel.apache.org/personalData|ns3|http://camel.apache.org/personalData2|"</span>)); +</span>namespacesFormat.setNamespaceMappings(namespaces); +namespacesFormat.setRootElement(<span class="code-quote">"person"</span>); +</pre> +</div></div> + +<p>And you can achieve the same in Spring DSL.</p> + +<h4><a shape="rect" name="XmlJson-Example"></a>Example</h4> + +<p>Using the namespace bindings in the Java snippet above on the following JSON string:</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<pre class="code-javascript">{ "name": "Raul", "surname": "Kripalani", "f": <span class="code-keyword">true</span>, "g": <span class="code-keyword">null</span>} +</pre> +</div></div> + +<p>Would yield the following XML:</p> + +<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> +<pre class="code-xml"><span class="code-tag"><person xmlns=<span class="code-quote">"http://camel.apache.org/default"</span> <span class="code-keyword">xmlns:ns1</span>=<span class="code-quote">"http://camel.apache.org/test1"</span>></span> + <span class="code-tag"><f></span>true<span class="code-tag"></f></span> + <span class="code-tag"><g null=<span class="code-quote">"true"</span>/></span> + <span class="code-tag"><name></span>Raul<span class="code-tag"></name></span> + <span class="code-tag"><surname <span class="code-keyword">xmlns:ns2</span>=<span class="code-quote">"http://camel.apache.org/personalData"</span> <span class="code-keyword">xmlns:ns3</span>=<span class="code-quote">"http://camel.apache.org/personalData2"</span>></span>Kripalani<span class="code-tag"></surname></span> +<span class="code-tag"></person></span> +</pre> +</div></div> + +<p>Remember that the JSON spec defines a JSON object as follows:</p> + +<blockquote> +<p>An object is an unordered set of name/value pairs. [].</p></blockquote> + +<p>That's why the elements are in a different order in the output XML.</p> <h3><a shape="rect" name="XmlJson-Dependencies"></a>Dependencies</h3> <p>To use the <a shape="rect" href="xmljson.html" title="XmlJson">XmlJson</a> dataformat in your camel routes you need to add the following dependency to your pom.</p> <div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent"> -<pre class="code-xml"> -<span class="code-tag"><dependency></span> +<pre class="code-xml"><span class="code-tag"><dependency></span> <span class="code-tag"><groupId></span>org.apache.camel<span class="code-tag"></groupId></span> <span class="code-tag"><artifactId></span>camel-xmljson<span class="code-tag"></artifactId></span> <span class="code-tag"><version></span>x.x.x<span class="code-tag"></version></span> |
| Powered by Nabble | Edit this page |
