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 18:15:29 UTC

Difference between bean(MyObject.class) and bean(new MyObject())

Hello

I have a route :

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

and I have a println inside the method parse, but it never gets printed.

If I put a log before the bean , then it works.

But if I simple replace the bean line with bean(new ComicBuilder(), .... )
then it works without putting the log command before.

Why is that ?



[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: Difference between bean(MyObject.class) and bean(new MyObject())

Posted by Willem Jiang <wi...@gmail.com>.
The second parameter of bean(Object, String) is for looking up the Object method.
"parse(${body[title]}, ${body[thumbnail][path]}, ${body[prices][0][price]}, ${body[id]})” cannot help camel to look up right method to use.

My suggestion is you can just pass the body object to the parse method directly.

--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On October 28, 2014 at 1:17:24 AM, Jonathan Vila Lopez (jonathan.vila@gmail.com) wrote:
> Hello
>  
> I have a route :
>  
> from("http://gat...URL....d805d").
> unmarshal().json(JsonLibrary.Jackson).
> split(simple("${body[data][results]}")).
> bean(ComicBuilder.class, "parse(${body[title]},
> ${body[thumbnail][path]}, ${body[prices][0][price]}, ${body[id]})").
> to("stream:out");
>  
> and I have a println inside the method parse, but it never gets printed.
>  
> If I put a log before the bean , then it works.
>  
> But if I simple replace the bean line with bean(new ComicBuilder(), .... )
> then it works without putting the log command before.
>  
> Why is that ?
>  
>  
>  
> [image: Inline image 2]
>  
> * Jonathan Vila **  
> *
>  
>  
> * jonathan.vila@gmail.com *
>  


Re: Difference between bean(MyObject.class) and bean(new MyObject())

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

This is my Git repo :
https://bitbucket.org/jvila/kata-marvelkata
Thank you
 El 27/10/2014 18:58, "Henryk Konsek" <he...@gmail.com> escribió:

> Hi Jonathan,
>
> > But if I simple replace the bean line with bean(new ComicBuilder(), ....
> )
> > then it works without putting the log command before.
>
> No real difference between bean(Foo.class, "method") and bean(new
> Foo(), "method") I'm aware of. Small Maven example reproducing the
> issue will be useful - this might be a bug.
>
> Cheers.
>
> --
> Henryk Konsek
> http://henryk-konsek.blogspot.com
>

Re: Difference between bean(MyObject.class) and bean(new MyObject())

Posted by Henryk Konsek <he...@gmail.com>.
Hi Jonathan,

> But if I simple replace the bean line with bean(new ComicBuilder(), .... )
> then it works without putting the log command before.

No real difference between bean(Foo.class, "method") and bean(new
Foo(), "method") I'm aware of. Small Maven example reproducing the
issue will be useful - this might be a bug.

Cheers.

-- 
Henryk Konsek
http://henryk-konsek.blogspot.com