camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Moulliard <ch0...@gmail.com>
Subject Re: Putting some Map values into a Bean
Date Tue, 28 Oct 2014 08:13:15 GMT
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 <jonathan.vila@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 <jonathan.vila@gmail.com>*
>>
>>
>>
>>
>


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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message