You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Jonathan Vila Lopez <jo...@gmail.com> on 2014/10/27 16:24:07 UTC

Putting some Map values into a Bean

Hello

I want to get some fields from a Map structure and put those fields into a
Bean.

I have this code :

from("http://....URL to a REST service that returns a JSon ...").
                unmarshal().json(JsonLibrary.Jackson).
                split(simple("${body[data][results]}")).
                *log("COMIC :
${body[id]}---${body[title]}----${body[prices][0][price]} ");*

After the log line I want to put those 2 values into a new Bean fields.

Is there any built-in transformation process inside camel that is capable
of create new POJOs and assign values ?

Kind regards.



[image: Inline image 2]

* Jonathan Vila    ** <https://www.twitter.com/jonathan_vila>
<http://www.linkedin.com/in/jonathanvila>*


* jonathan.vila@gmail.com <jo...@gmail.com>*

Re: Putting some Map values into a Bean

Posted by Charles Moulliard <ch...@gmail.com>.
Hi Jonathan,

I would like to suggest that you generate the POJOS classes from the JSON
response that you are getting from Marvel RESTfull Gateway using by example
this online tool (http://www.jsonschema2pojo.org/). The classes generated
could be next integrated with your project and used by Jackson to map the
JSON response with the POJOS

        <dataFormats>
            <json id="json-marvel" library="Jackson"
unmarshalTypeName="org.marvel.model.Record"/>
        </dataFormats>
        ....
        <unmarshal ref="json-marvel"/>

You will be able to navigate using the simple language within the objects

example :

<log message="ID : ${header.marvelID}"/>
 <log message="Name : ${body.data.results[0].name}"/>
<log message="Description : ${body.data.results[0].description}"/>

Regards,


On Mon, Oct 27, 2014 at 6:10 PM, Jonathan Vila Lopez <
jonathan.vila@gmail.com> wrote:

> Hello
>
> Thanks to the help of Christian......now it works :
>
> from("http://gateway.m...URL.....805d").
>                 unmarshal().json(JsonLibrary.Jackson).
>                 split(simple("${body[data][results]}")).
>                * bean(new ComicBuilder(), "parse(${body[title]},
> ${body[thumbnail][path]}, ${body[prices][0][price]}, ${body[id]})").*
>                 to("stream:out");
>
> Now I'm using a builder that creates new MarvelComicReduced instances....
>
> Is there any way to not use a custom Builder and that Camel automatically
> creates new POJOS using the final POJO constructor ?
>
> Kind regards.
>
>
>
>
> [image: Inline image 2]
>
> * Jonathan Vila    ** <https://www.twitter.com/jonathan_vila>
> <http://www.linkedin.com/in/jonathanvila>*
>
>
> * jonathan.vila@gmail.com <jo...@gmail.com>*
>
>
>
>
> On Mon, Oct 27, 2014 at 4:24 PM, Jonathan Vila Lopez <
> jonathan.vila@gmail.com> wrote:
>
>> Hello
>>
>> I want to get some fields from a Map structure and put those fields into
>> a Bean.
>>
>> I have this code :
>>
>> from("http://....URL to a REST service that returns a JSon ...").
>>                 unmarshal().json(JsonLibrary.Jackson).
>>                 split(simple("${body[data][results]}")).
>>                 *log("COMIC :
>> ${body[id]}---${body[title]}----${body[prices][0][price]} ");*
>>
>> After the log line I want to put those 2 values into a new Bean fields.
>>
>> Is there any built-in transformation process inside camel that is capable
>> of create new POJOs and assign values ?
>>
>> Kind regards.
>>
>>
>>
>> [image: Inline image 2]
>>
>> * Jonathan Vila    ** <https://www.twitter.com/jonathan_vila>
>> <http://www.linkedin.com/in/jonathanvila>*
>>
>>
>> * jonathan.vila@gmail.com <jo...@gmail.com>*
>>
>>
>>
>>
>


-- 
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog :  http://cmoulliard.github.io

Re: Putting some Map values into a Bean

Posted by Jonathan Vila Lopez <jo...@gmail.com>.
Hello

Thanks to the help of Christian......now it works :

from("http://gateway.m...URL.....805d").
                unmarshal().json(JsonLibrary.Jackson).
                split(simple("${body[data][results]}")).
               * bean(new ComicBuilder(), "parse(${body[title]},
${body[thumbnail][path]}, ${body[prices][0][price]}, ${body[id]})").*
                to("stream:out");

Now I'm using a builder that creates new MarvelComicReduced instances....

Is there any way to not use a custom Builder and that Camel automatically
creates new POJOS using the final POJO constructor ?

Kind regards.




[image: Inline image 2]

* Jonathan Vila    ** <https://www.twitter.com/jonathan_vila>
<http://www.linkedin.com/in/jonathanvila>*


* jonathan.vila@gmail.com <jo...@gmail.com>*




On Mon, Oct 27, 2014 at 4:24 PM, Jonathan Vila Lopez <
jonathan.vila@gmail.com> wrote:

> Hello
>
> I want to get some fields from a Map structure and put those fields into a
> Bean.
>
> I have this code :
>
> from("http://....URL to a REST service that returns a JSon ...").
>                 unmarshal().json(JsonLibrary.Jackson).
>                 split(simple("${body[data][results]}")).
>                 *log("COMIC :
> ${body[id]}---${body[title]}----${body[prices][0][price]} ");*
>
> After the log line I want to put those 2 values into a new Bean fields.
>
> Is there any built-in transformation process inside camel that is capable
> of create new POJOs and assign values ?
>
> Kind regards.
>
>
>
> [image: Inline image 2]
>
> * Jonathan Vila    ** <https://www.twitter.com/jonathan_vila>
> <http://www.linkedin.com/in/jonathanvila>*
>
>
> * jonathan.vila@gmail.com <jo...@gmail.com>*
>
>
>
>