You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Vaïsse-Lesteven Arthur <ar...@yahoo.fr> on 2014/11/26 16:40:10 UTC

[Rest DSL] Automatic convertion of body to java.util.Map . How to fix it ?

Hi every one!

I'm trying to create a RESTful API using the Rest DSL capacity of the
release 2.14.0 of Camel.

My problem currently come from the fact that the body of the Exchange is
automatically casted into a java Map object.

Here come a reduced example (I tried to make it as small as possible...) : 

This is my XML camel context file. It defines a rest API that accept
conection on http://localhost:5117/rest/speakers/{speaker_id} and that
expect HTTP put with a Json object that is serializable into a SpeakerPojo
object.


The java classes that backed this endpoint are:
The SpeakerPojo object:

And the bean used as endpoint :


Finally I use this code to call the restAPI :


These call make the following error to occur:


The message body have automatically transformed into a HashMap. So I tried
to add before the unmarshaller call 
I then got this :

And a parsing error as double quote are now absent due to the double
conversion from string to map and from map to string.

Am I doing something wrong ? Can I dis-activate the auto-casting of the
payload to HashMap ?

Thank in advance!



--
View this message in context: http://camel.465427.n5.nabble.com/Rest-DSL-Automatic-convertion-of-body-to-java-util-Map-How-to-fix-it-tp5759648.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [Rest DSL] Automatic convertion of body to java.util.Map . How to fix it ?

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

People is very welcome to help with docs and other contributions
http://camel.apache.org/contributing.html
http://camel.apache.org/how-do-i-edit-the-website.html

Just a note that the Camel DSL in Java and XML is 99% similar, so its
actually easy when you know this. also in XML use the power of the
tooling to help assist what xml types etc you can do, eg usually its
pressing ctrl + space etc.

On Thu, Nov 27, 2014 at 9:01 AM, Vaïsse-Lesteven Arthur
<ar...@yahoo.fr> wrote:
> It works!
>
> Using :
>
>
> Maybe adding the corresponding documentation for XML synthax to the
> documentation could be a good idea. I read the doc many time without
> understanding that this part also apply for XML.
>
> Anyway, thank you!
> Arthur.
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Rest-DSL-Automatic-convertion-of-body-to-java-util-Map-How-to-fix-it-tp5759648p5759689.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: [Rest DSL] Automatic convertion of body to java.util.Map . How to fix it ?

Posted by Vaïsse-Lesteven Arthur <ar...@yahoo.fr>.
It works!

Using :


Maybe adding the corresponding documentation for XML synthax to the
documentation could be a good idea. I read the doc many time without
understanding that this part also apply for XML.

Anyway, thank you!
Arthur.




--
View this message in context: http://camel.465427.n5.nabble.com/Rest-DSL-Automatic-convertion-of-body-to-java-util-Map-How-to-fix-it-tp5759648p5759689.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: [Rest DSL] Automatic convertion of body to java.util.Map . How to fix it ?

Posted by Taariq Levack <ta...@gmail.com>.
Hi
You need to set the type as SpeakerPojo.class
I don't see a spring example here setting type but it should work the same as java so adjust accordingly.
http://camel.apache.org/rest-dsl.html

Taariq

> On 26 Nov 2014, at 17:40, Vaïsse-Lesteven Arthur <ar...@yahoo.fr> wrote:
> 
> Hi every one!
> 
> I'm trying to create a RESTful API using the Rest DSL capacity of the
> release 2.14.0 of Camel.
> 
> My problem currently come from the fact that the body of the Exchange is
> automatically casted into a java Map object.
> 
> Here come a reduced example (I tried to make it as small as possible...) : 
> 
> This is my XML camel context file. It defines a rest API that accept
> conection on http://localhost:5117/rest/speakers/{speaker_id} and that
> expect HTTP put with a Json object that is serializable into a SpeakerPojo
> object.
> 
> 
> The java classes that backed this endpoint are:
> The SpeakerPojo object:
> 
> And the bean used as endpoint :
> 
> 
> Finally I use this code to call the restAPI :
> 
> 
> These call make the following error to occur:
> 
> 
> The message body have automatically transformed into a HashMap. So I tried
> to add before the unmarshaller call 
> I then got this :
> 
> And a parsing error as double quote are now absent due to the double
> conversion from string to map and from map to string.
> 
> Am I doing something wrong ? Can I dis-activate the auto-casting of the
> payload to HashMap ?
> 
> Thank in advance!
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Rest-DSL-Automatic-convertion-of-body-to-java-util-Map-How-to-fix-it-tp5759648.html
> Sent from the Camel - Users mailing list archive at Nabble.com.