You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "anish.somadevan" <ne...@gmail.com> on 2015/09/01 19:46:27 UTC

Re: JSON to XML Conversion

Yes, i have it within the camelContext tags. But i get the same error as
mentioned earlier,

  [com.acp.adapter.cameladapter.CamelOutboundAdapter] (Camel (camelAgent)
thread #6 - JmsConsumer[ISEEOutboundQueue]) CamelOutboundAdapter exception:
Failed to create route parseJSON at: >>> Unmarshal[ref:xmljsonWithOptions]
<<< in route: Route[[From[direct:inter2]] ->
[Unmarshal[ref:xmljsonWithOpt... because of Cannot find data format in
registry with ref: xmljsonWithOptions



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

Re: JSON to XML Conversion

Posted by "anish.somadevan" <ne...@gmail.com>.
This works!! . Thanks a lot Yogesh and Raul for helping me resolve this :)
Really appreciate it.

PS. Am facing a similar issue related to registry
(http://camel.465427.n5.nabble.com/PEM-File-for-Authentication-in-route-td5771084.html#a5771109).
It would be really helpful if you can have a look at this when you find
time.

Thanks,
Anish





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

Re: JSON to XML Conversion

Posted by Raul Kripalani <ra...@evosent.com>.
I'm not suggesting that you use JAXB. I just wanted you to try defining the
JSON to XML data format nested inside the unmarshal.
On 2 Sep 2015 02:06, "anish.somadevan" <ne...@gmail.com> wrote:

> Am actually trying to convert a JSON response from an API to XML, and i
> don't
> think it can be done using JAXB. Please correct me if am wrong.
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/JSON-to-XML-Conversion-tp5771032p5771141.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: JSON to XML Conversion

Posted by "anish.somadevan" <ne...@gmail.com>.
Am actually trying to convert a JSON response from an API to XML, and i don't
think it can be done using JAXB. Please correct me if am wrong.





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

Re: JSON to XML Conversion

Posted by Raul Kripalani <ra...@evosent.com>.
You don't need to use ref. Have a look at the first XML example for the
JAXB data format here: http://camel.apache.org/jaxb.html.

Raúl. No
On 2 Sep 2015 01:25, "anish.somadevan" <ne...@gmail.com> wrote:

> Am not sure if i have implemented it as you said. This is what i have in my
> route now,
>
> <routes xmlns="http://camel.apache.org/schema/spring">
> <unmarshal>
>     <xmljson id="xmljson"/>
>     <xmljson id="xmljsonWithOptions" forceTopLevelObject="true"
> trimSpaces="true" rootName="newRoot" skipNamespaces="true"
> removeNamespacePrefixes="true" expandableProperties="d e"/>
> </unmarshal>
>
> <to uri="direct:inter2" />
>     </route>
>
>         <route id="parseJSON">
>         <from uri="direct:inter2" />
>
>         <unmarshal ref="xmljsonWithOptions"/>
>         <to uri="direct:inter3" />
>     </route>
>
>
> I still get the same error
>
>  Failed to create route parseJSON at: >>> Unmarshal[ref:xmljsonWithOptions]
> <<< in route: Route[[From[direct:inter2]] ->
> [Unmarshal[ref:xmljsonWithOpt... because of Cannot find data format in
> registry with ref: xmljsonWithOptions
>
>
> But when i have just "xmljson" in the route, everything works fine,
>
> <to uri="direct:inter2" />
>     </route>
>
>         <route id="parseJSON">
>         <from uri="direct:inter2" />
>
>         <unmarshal ref="xmljson"/>
>         <to uri="direct:inter3" />
>     </route>
>
> Can you let me know your thoughts on this. Am facing issue wherever am
> trying to refer something from registry.
>
> Thanks,
> Anish
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/JSON-to-XML-Conversion-tp5771032p5771139.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: JSON to XML Conversion

Posted by "anish.somadevan" <ne...@gmail.com>.
Am not sure if i have implemented it as you said. This is what i have in my
route now,

<routes xmlns="http://camel.apache.org/schema/spring">
<unmarshal>
    <xmljson id="xmljson"/>
    <xmljson id="xmljsonWithOptions" forceTopLevelObject="true"
trimSpaces="true" rootName="newRoot" skipNamespaces="true"
removeNamespacePrefixes="true" expandableProperties="d e"/>
</unmarshal>

<to uri="direct:inter2" />
    </route>

        <route id="parseJSON">
        <from uri="direct:inter2" />

        <unmarshal ref="xmljsonWithOptions"/>
        <to uri="direct:inter3" />
    </route>


I still get the same error

 Failed to create route parseJSON at: >>> Unmarshal[ref:xmljsonWithOptions]
<<< in route: Route[[From[direct:inter2]] ->
[Unmarshal[ref:xmljsonWithOpt... because of Cannot find data format in
registry with ref: xmljsonWithOptions


But when i have just "xmljson" in the route, everything works fine,

<to uri="direct:inter2" />
    </route>

        <route id="parseJSON">
        <from uri="direct:inter2" />

        <unmarshal ref="xmljson"/>
        <to uri="direct:inter3" />
    </route>

Can you let me know your thoughts on this. Am facing issue wherever am
trying to refer something from registry. 

Thanks,
Anish



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

Re: JSON to XML Conversion

Posted by Raul Kripalani <ra...@evosent.com>.
Aha! So you are using the <routes/> XML approach to load your routes.

You can define data formats in two places: either (a) inside your Camel
Context, which, if you are using exactly this approach [1], is being
configured programmatically, or (b) inline inside your marshal / unmarshal
XML element.

I would suggest you try (b):

<unmarshal>
    <xmljson... />
</unmarshal>

[1] http://camel.apache.org/loading-routes-from-xml-files.html

Regards,
Raúl.
On 1 Sep 2015 23:55, "anish.somadevan" <ne...@gmail.com> wrote:

> I currently have this as the first line in my XML.
>
> <routes xmlns="http://camel.apache.org/schema/spring">
> And then i have defined the camelContext tags,
> <camelContext>
> <dataFormats>
>     <xmljson id="xmljson"/>
>     <xmljson id="xmljsonWithOptions" forceTopLevelObject="true"
> trimSpaces="true" rootName="newRoot" skipNamespaces="true"
>              removeNamespacePrefixes="true" expandableProperties="d e"/>
> </dataFormats>
> </camelContext>
> </routes>
>
> When i tried to give camelContext as the first line, I get this error
>
> unexpected element (uri:"http://camel.apache.org/schema/spring",
> local:"camelContext"). Expected elements are
> <{http://camel.apache.org/schema/spring}aggregate>,<{
> http://camel.apache.org/schema/spring}aop>,<{
> http://camel.apache.org/schema/spring}avro>,<{
> http://camel.apache.org/schema/spring}batchResequencerConfig>,<{
> http://camel.apache.org/schema/spring}bean>,<{
> http://camel.apache.org/schema/spring}beanio>,<{
> http://camel.apache.org/schema/spring}bindy>,<{
> http://camel.apache.org/schema/spring}castor>,<{
> http://camel.apache.org/schema/spring}choice>,<{
> http://camel.apache.org/schema/spring}constant>,<{
> http://camel.apache.org/schema/spring}contextScan>,<{
> http://camel.apache.org/schema/spring}convertBodyTo>,<{
> http://camel.apache.org/schema/spring}crypto>,<{
> http://camel.apache.org/schema/spring}csv>,<{
> http://camel.apache.org/schema/spring}customDataFormat>,<{
> http://camel.apache.org/schema/spring}customLoadBalancer>,<{
> http://camel.apache.org/schema/spring}dataFormats>,<{
> http://camel.apache.org/schema/spring}delay>,<{
> http://camel.apache.org/schema/spring}description>,<{
> http://camel.apache.org/schema/spring}doCatch>,<{
> http://camel.apache.org/schema/spring}doFinally>,<{
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/JSON-to-XML-Conversion-tp5771032p5771137.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: JSON to XML Conversion

Posted by "anish.somadevan" <ne...@gmail.com>.
I currently have this as the first line in my XML.

<routes xmlns="http://camel.apache.org/schema/spring">
And then i have defined the camelContext tags,
<camelContext>
<dataFormats>
    <xmljson id="xmljson"/>
    <xmljson id="xmljsonWithOptions" forceTopLevelObject="true"
trimSpaces="true" rootName="newRoot" skipNamespaces="true"
             removeNamespacePrefixes="true" expandableProperties="d e"/>
</dataFormats>
</camelContext>
</routes>

When i tried to give camelContext as the first line, I get this error

unexpected element (uri:"http://camel.apache.org/schema/spring",
local:"camelContext"). Expected elements are
<{http://camel.apache.org/schema/spring}aggregate>,<{http://camel.apache.org/schema/spring}aop>,<{http://camel.apache.org/schema/spring}avro>,<{http://camel.apache.org/schema/spring}batchResequencerConfig>,<{http://camel.apache.org/schema/spring}bean>,<{http://camel.apache.org/schema/spring}beanio>,<{http://camel.apache.org/schema/spring}bindy>,<{http://camel.apache.org/schema/spring}castor>,<{http://camel.apache.org/schema/spring}choice>,<{http://camel.apache.org/schema/spring}constant>,<{http://camel.apache.org/schema/spring}contextScan>,<{http://camel.apache.org/schema/spring}convertBodyTo>,<{http://camel.apache.org/schema/spring}crypto>,<{http://camel.apache.org/schema/spring}csv>,<{http://camel.apache.org/schema/spring}customDataFormat>,<{http://camel.apache.org/schema/spring}customLoadBalancer>,<{http://camel.apache.org/schema/spring}dataFormats>,<{http://camel.apache.org/schema/spring}delay>,<{http://camel.apache.org/schema/spring}description>,<{http://camel.apache.org/schema/spring}doCatch>,<{http://camel.apache.org/schema/spring}doFinally>,<{




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