You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Gnanaguru S <gn...@gmail.com> on 2015/05/13 09:09:42 UTC

Handle white space - JSON to XML using XMLJSON component

Hi Guys,

I recently got impressed with xmljson component, it does pretty good job in
transforming JSON to XML and vice versa. 

I have a JSON payload which has keys with white space, xmljson doesnt accept
JSON keys with whitespaces and it throws the exception shown below. 

This is my JSON payload:

{
  "Format": "JSON",
  "TestData": {
   * "Key with Spaces in it"*: {
      "And Again": {
        "ChildKey1": "Financial",
        "ChildKey2": null
      },
.........
.....

Is there a camel way to handle this ? Or I have to write a processor to
remove white spaces only on the keys ?

nu.xom.IllegalNameException: 0x20 is not a legal NCName character
	at nu.xom.Verifier.throwIllegalNameException(Unknown Source)
	at nu.xom.Verifier.checkNCName(Unknown Source)
	at nu.xom.Element._setLocalName(Unknown Source)
	at nu.xom.Element.<init>(Unknown Source)
	at nu.xom.Element.<init>(Unknown Source)
	at net.sf.json.xml.XMLSerializer.newElement(XMLSerializer.java:869)
	at net.sf.json.xml.XMLSerializer.processJSONObject(XMLSerializer.java:989)
	at net.sf.json.xml.XMLSerializer.processJSONValue(XMLSerializer.java:1040)
	at net.sf.json.xml.XMLSerializer.processJSONObject(XMLSerializer.java:990)
	at net.sf.json.xml.XMLSerializer.write(XMLSerializer.java:605)
	at net.sf.json.xml.XMLSerializer.write(XMLSerializer.java:570)
	at
org.apache.camel.dataformat.xmljson.XmlJsonDataFormat.convertToXMLUsingEncoding(XmlJsonDataFormat.java:191)
	at
org.apache.camel.dataformat.xmljson.XmlJsonDataFormat.unmarshal(XmlJsonDataFormat.java:186)
	at
org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:65)
	at
org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:163)
	at org.apache.camel.processor.interceptor.Debug$1.process(Debug.java:50)
	at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:91)
	at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
	at
org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:51)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
	at
org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:73)
	at
org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:378)
	at
org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:346)
	at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:242)
	at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:346)
	at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:201)
	at
org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:128)
	at
org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:132)
	at
org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:149)
	at
org.apache.camel.impl.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:297)
	at 

Regards
Guru



--
View this message in context: http://camel.465427.n5.nabble.com/Handle-white-space-JSON-to-XML-using-XMLJSON-component-tp5767042.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handle white space - JSON to XML using XMLJSON component

Posted by Pontus Ullgren <ul...@gmail.com>.
The xmljson component is using json-lib[1] to do the actual work. Check the
documentation for that project or put a question in there forum if there is
some configuration that can be set to properly handle whitespaces.

[1] http://json-lib.sourceforge.net/

On Thu, 14 May 2015 08:48 Gnanaguru S <gn...@gmail.com> wrote:

> Well, I understand your point. But any valid string is a valid JSON key.
>
> We cant blame the JSON payload at this point :(
>
> So any ideas ? Or best way to handle these kind of scenarios ?
>
> Cheers
> Guru
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Handle-white-space-JSON-to-XML-using-XMLJSON-component-tp5767042p5767084.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Handle white space - JSON to XML using XMLJSON component

Posted by Gnanaguru S <gn...@gmail.com>.
Well, I understand your point. But any valid string is a valid JSON key. 

We cant blame the JSON payload at this point :(

So any ideas ? Or best way to handle these kind of scenarios ?

Cheers
Guru



--
View this message in context: http://camel.465427.n5.nabble.com/Handle-white-space-JSON-to-XML-using-XMLJSON-component-tp5767042p5767084.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Handle white space - JSON to XML using XMLJSON component

Posted by Reji Mathews <co...@gmail.com>.
Hi Guru

I really wonder if XML element name supports white spaces and if its
legal.. If not, it shudn't be for json either.

Anything which comes with a space might be interpreted as XML attribute.

Think this way! What will a classname look like when it gets converted to
equivalent java classes :-)

Cheers
Reji


On Wed, May 13, 2015 at 12:39 PM, Gnanaguru S <gn...@gmail.com> wrote:

> Hi Guys,
>
> I recently got impressed with xmljson component, it does pretty good job in
> transforming JSON to XML and vice versa.
>
> I have a JSON payload which has keys with white space, xmljson doesnt
> accept
> JSON keys with whitespaces and it throws the exception shown below.
>
> This is my JSON payload:
>
> {
>   "Format": "JSON",
>   "TestData": {
>    * "Key with Spaces in it"*: {
>       "And Again": {
>         "ChildKey1": "Financial",
>         "ChildKey2": null
>       },
> .........
> .....
>
> Is there a camel way to handle this ? Or I have to write a processor to
> remove white spaces only on the keys ?
>
> nu.xom.IllegalNameException: 0x20 is not a legal NCName character
>         at nu.xom.Verifier.throwIllegalNameException(Unknown Source)
>         at nu.xom.Verifier.checkNCName(Unknown Source)
>         at nu.xom.Element._setLocalName(Unknown Source)
>         at nu.xom.Element.<init>(Unknown Source)
>         at nu.xom.Element.<init>(Unknown Source)
>         at net.sf.json.xml.XMLSerializer.newElement(XMLSerializer.java:869)
>         at
> net.sf.json.xml.XMLSerializer.processJSONObject(XMLSerializer.java:989)
>         at
> net.sf.json.xml.XMLSerializer.processJSONValue(XMLSerializer.java:1040)
>         at
> net.sf.json.xml.XMLSerializer.processJSONObject(XMLSerializer.java:990)
>         at net.sf.json.xml.XMLSerializer.write(XMLSerializer.java:605)
>         at net.sf.json.xml.XMLSerializer.write(XMLSerializer.java:570)
>         at
>
> org.apache.camel.dataformat.xmljson.XmlJsonDataFormat.convertToXMLUsingEncoding(XmlJsonDataFormat.java:191)
>         at
>
> org.apache.camel.dataformat.xmljson.XmlJsonDataFormat.unmarshal(XmlJsonDataFormat.java:186)
>         at
>
> org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:65)
>         at
>
> org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:163)
>         at
> org.apache.camel.processor.interceptor.Debug$1.process(Debug.java:50)
>         at
>
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:91)
>         at
>
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
>         at
>
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
>         at
>
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
>         at
>
> org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:51)
>         at
>
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
>         at
>
> org.apache.camel.processor.UnitOfWorkProducer.process(UnitOfWorkProducer.java:73)
>         at
> org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:378)
>         at
> org.apache.camel.impl.ProducerCache$2.doInProducer(ProducerCache.java:346)
>         at
> org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:242)
>         at
> org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:346)
>         at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:201)
>         at
>
> org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:128)
>         at
>
> org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:132)
>         at
>
> org.apache.camel.impl.DefaultProducerTemplate.sendBody(DefaultProducerTemplate.java:149)
>         at
>
> org.apache.camel.impl.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:297)
>         at
>
> Regards
> Guru
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Handle-white-space-JSON-to-XML-using-XMLJSON-component-tp5767042.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>