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/14 14:47:06 UTC

JSON to XML Mapping/Transformation

How is JSON to XML mapping is generally done in Camel ?

We have xmljson component, but it doesn't do some classic json use cases. 

In my case I have incoming JSON payload which has all kind of possible
symbols supported by a String which includes white spaces as well. 

I can use JACKSON to convert JSON to POJOs, then from POJOs I can convert to
XML straight away using XSTREAM. But again this xml is again going to be
tough to handle, because its all going to be maps and entries. 

My incoming JSON looks like this:

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

Any thoughts / suggestions ? I would love to hear some ideas which is
Camelish :)

Regards
Guru
@tallguru



--
View this message in context: http://camel.465427.n5.nabble.com/JSON-to-XML-Mapping-Transformation-tp5767112.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JSON to XML Mapping/Transformation

Posted by Gnanaguru S <gn...@gmail.com>.
One way to handle this issue:
http://stackoverflow.com/questions/30228343/replace-whitespace-in-json-keys/30228588?noredirect=1#comment48726021_30228588


Regards
Guru



--
View this message in context: http://camel.465427.n5.nabble.com/JSON-to-XML-Mapping-Transformation-tp5767112p5767231.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JSON to XML Mapping/Transformation

Posted by Gnanaguru S <gn...@gmail.com>.
Hey, Thanks. Can you elaborate a bit ? Any samples ? References  to your
approach ?

Regards
Guru



--
View this message in context: http://camel.465427.n5.nabble.com/JSON-to-XML-Mapping-Transformation-tp5767112p5767140.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JSON to XML Mapping/Transformation

Posted by sekaijin <je...@sap.aphp.fr>.
I use a double annotation on a pojo
and marshaller unmarshaller.


A+JYT



--
View this message in context: http://camel.465427.n5.nabble.com/JSON-to-XML-Mapping-Transformation-tp5767112p5767138.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: JSON to XML Mapping/Transformation

Posted by erd <ev...@gmail.com>.
Hello,

I had a similar situation. From my google-fu, it seems like Unmarshalling
with jackson is your best bet. The 'nesting' is a bit of a curveball. I
found explicitly binding the POJO is the easiest for uniform keys- I think
your POJO structure should look something like

public class myJson{
@JsonProperty("Format")
String format;
@JsonProperty("TestData")
TestData testData;

     class TestData{
     @JsonProperty("Key with Spaces in it")
      KeyWithSpacesInIt keyWspaces;
      //setters     
      }
     ...
 //setters
 //default constructor
}
just define an object for each 'layer'.
I hope that answers it. I'm not terribly familiar with Xstream, however.



--
View this message in context: http://camel.465427.n5.nabble.com/JSON-to-XML-Mapping-Transformation-tp5767112p5767116.html
Sent from the Camel - Users mailing list archive at Nabble.com.