REST Reply: convert XML to JSON in Spring DSL

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

REST Reply: convert XML to JSON in Spring DSL

Mark Lumsden
I am a newbie to Camel, Spring, Java (and everything about EIP!). I'm trying to use Spring DSL to transform a REST GET request which provides XML data but change it in to JSON for the client. Here is the abbreviated XML from the Camel Context which just returns XML:

[route id="api-route2"]
    [from id="_route2" uri="direct:obj2"/]
    [to id="_to2" uri="http://localhost:8081/obj2/index.xml?bridgeEndpoint=true"/]
[/route]

I get the XML document returned AOK from the local server via Camel, but is it possible to change the format of the data just using Spring DSL in Camel? I see quite a lot of examples on the web of using Java DSL to use marshaling to do the translation.

Any help much appreciated.
Mark
Reply | Threaded
Open this post in threaded view
|

RE: REST Reply: convert XML to JSON in Spring DSL

Gupta, Madhu
Hi

Look at below sample.  This example refers to JSON to xml. But we were told by Redhat that  that similar approach can be used in doing XML to json translation.

https://github.com/sigreen/vscode-fuse-atlasmap

Thanks
Madhu Gupta

-----Original Message-----
From: Mark Lumsden <[hidden email]>
Sent: Tuesday, February 11, 2020 1:05 PM
To: [hidden email]
Subject: REST Reply: convert XML to JSON in Spring DSL

I am a newbie to Camel, Spring, Java (and everything about EIP!). I'm trying to use Spring DSL to transform a REST GET request which provides XML data but change it in to JSON for the client. Here is the abbreviated XML from the Camel Context which just returns XML:

[route id="api-route2"]
    [from id="_route2" uri="direct:obj2"/]
    [to id="_to2" uri="http://localhost:8081/obj2/index.xml?bridgeEndpoint=true"/]
[/route]

I get the XML document returned AOK from the local server via Camel, but is it possible to change the format of the data just using Spring DSL in Camel? I see quite a lot of examples on the web of using Java DSL to use marshaling to do the translation.

Any help much appreciated.
Mark
Reply | Threaded
Open this post in threaded view
|

Re: REST Reply: convert XML to JSON in Spring DSL

Michael Kay
In reply to this post by Mark Lumsden
There are many ways of doing XML to JSON conversion, but they all produce different results. If you have to deliver the JSON in some particular externally-defined format, then it's very likely that none of the converters will produce exactly what you want, and you will need to do some coding (XSLT 3.0 is convenient for this). But if the requirement is "any old JSON" then any of the libraries will do.

Michael Kay

> On 11 Feb 2020, at 19:05, Mark Lumsden <[hidden email]> wrote:
>
> I am a newbie to Camel, Spring, Java (and everything about EIP!). I'm trying to use Spring DSL to transform a REST GET request which provides XML data but change it in to JSON for the client. Here is the abbreviated XML from the Camel Context which just returns XML:
>
> [route id="api-route2"]
>    [from id="_route2" uri="direct:obj2"/]
>    [to id="_to2" uri="http://localhost:8081/obj2/index.xml?bridgeEndpoint=true"/]
> [/route]
>
> I get the XML document returned AOK from the local server via Camel, but is it possible to change the format of the data just using Spring DSL in Camel? I see quite a lot of examples on the web of using Java DSL to use marshaling to do the translation.
>
> Any help much appreciated.
> Mark

Reply | Threaded
Open this post in threaded view
|

RE: REST Reply: convert XML to JSON in Spring DSL

Mark Lumsden
Hi Michael,

Any old JSON will do at the moment. I found an example from the mailing list that works fine for PoC.

camel.465427.n5.nabble.com/How-to-specify-types-in-marshalling-from-XML-to-JSON-td5775980.html<https://camel.465427.n5.nabble.com/How-to-specify-types-in-marshalling-from-XML-to-JSON-td5775980.html>

Thanks Madhu for your feedback as well.
All the best!

Mark


From: Michael Kay<mailto:[hidden email]>
Sent: 11 February 2020 20:24
To: [hidden email]<mailto:[hidden email]>
Subject: Re: REST Reply: convert XML to JSON in Spring DSL

There are many ways of doing XML to JSON conversion, but they all produce different results. If you have to deliver the JSON in some particular externally-defined format, then it's very likely that none of the converters will produce exactly what you want, and you will need to do some coding (XSLT 3.0 is convenient for this). But if the requirement is "any old JSON" then any of the libraries will do.

Michael Kay

> On 11 Feb 2020, at 19:05, Mark Lumsden <[hidden email]> wrote:
>
> I am a newbie to Camel, Spring, Java (and everything about EIP!). I'm trying to use Spring DSL to transform a REST GET request which provides XML data but change it in to JSON for the client. Here is the abbreviated XML from the Camel Context which just returns XML:
>
> [route id="api-route2"]
>    [from id="_route2" uri="direct:obj2"/]
>    [to id="_to2" uri="http://localhost:8081/obj2/index.xml?bridgeEndpoint=true"/<http://localhost:8081/obj2/index.xml?bridgeEndpoint=true%22/>]
> [/route]
>
> I get the XML document returned AOK from the local server via Camel, but is it possible to change the format of the data just using Spring DSL in Camel? I see quite a lot of examples on the web of using Java DSL to use marshaling to do the translation.
>
> Any help much appreciated.
> Mark

Reply | Threaded
Open this post in threaded view
|

Re: REST Reply: convert XML to JSON in Spring DSL

skin27
As mister Kay already mentioned if you want full control the best way to go
is with XSLT 3.0. If you just need a simple approach in plain Java, you can
try DocConverter (https://github.com/assimbly/docconverter).

Kind regards,

Raymond

Op wo 12 feb. 2020 om 15:31 schreef Mark Lumsden <[hidden email]>:

> Hi Michael,
>
> Any old JSON will do at the moment. I found an example from the mailing
> list that works fine for PoC.
>
>
> camel.465427.n5.nabble.com/How-to-specify-types-in-marshalling-from-XML-to-JSON-td5775980.html
> <
> https://camel.465427.n5.nabble.com/How-to-specify-types-in-marshalling-from-XML-to-JSON-td5775980.html
> >
>
> Thanks Madhu for your feedback as well.
> All the best!
>
> Mark
>
>
> From: Michael Kay<mailto:[hidden email]>
> Sent: 11 February 2020 20:24
> To: [hidden email]<mailto:[hidden email]>
> Subject: Re: REST Reply: convert XML to JSON in Spring DSL
>
> There are many ways of doing XML to JSON conversion, but they all produce
> different results. If you have to deliver the JSON in some particular
> externally-defined format, then it's very likely that none of the
> converters will produce exactly what you want, and you will need to do some
> coding (XSLT 3.0 is convenient for this). But if the requirement is "any
> old JSON" then any of the libraries will do.
>
> Michael Kay
>
> > On 11 Feb 2020, at 19:05, Mark Lumsden <[hidden email]> wrote:
> >
> > I am a newbie to Camel, Spring, Java (and everything about EIP!). I'm
> trying to use Spring DSL to transform a REST GET request which provides XML
> data but change it in to JSON for the client. Here is the abbreviated XML
> from the Camel Context which just returns XML:
> >
> > [route id="api-route2"]
> >    [from id="_route2" uri="direct:obj2"/]
> >    [to id="_to2" uri="
> http://localhost:8081/obj2/index.xml?bridgeEndpoint=true"/<
> http://localhost:8081/obj2/index.xml?bridgeEndpoint=true%22/>]
> > [/route]
> >
> > I get the XML document returned AOK from the local server via Camel, but
> is it possible to change the format of the data just using Spring DSL in
> Camel? I see quite a lot of examples on the web of using Java DSL to use
> marshaling to do the translation.
> >
> > Any help much appreciated.
> > Mark
>
>