No it does not.

Its you who convert the message to a String in the processor code.
 String body = exchange.getIn().getBody(String.class);

You can just do
Object body = exchange.getIn().getBody();



On Thu, Nov 8, 2012 at 9:02 AM, hhenne <[email protected]> wrote:
> Documentation and samples says, that ProducerTemplate.sendBody should send
> any Object.
> However in my setup, it seems to call toString on the object, so it's not
> the real object that is sent - unless the object is a String.
>
> Here is my test, which prints: *************process body: :
> ProducerTemplateTest$A@b8deef - because my object does not have overrided
> toString. If I override toString (uncommenting it) it will print 'hello' all
> right.
>
>
> import org.apache.camel.Exchange;
> import org.apache.camel.Processor;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.test.junit4.CamelTestSupport;
> import org.junit.Test;
>
> public class ProducerTemplateTest extends CamelTestSupport {
>
>     @Test
>     public void firstTest() throws Exception {
>         ProducerTemplate producer = context.createProducerTemplate();
>         producer.sendBody("direct:start", new A());
>     }
>
>         @Override
>         protected RouteBuilder createRouteBuilder() throws Exception {
>                 return new RouteBuilder() {
>                         @Override
>                         public void configure() throws Exception {
>                                 from("direct:start")
>                                 .process(new Processor() {
>                                         public void process(Exchange 
> exchange) throws Exception {
>                                 String body = 
> exchange.getIn().getBody(String.class);
>                                 System.out.println("*************process 
> body: : " +
> body);
>                                 exchange.getIn().setBody(body);
>                                         }
>                                         })
>                                 .to("mock:result");
>                         }
>                 };
>   }
>
>
>     class A {
>        String s = "hello";
>
> //       public String toString(){
> //         return s;
> //       }
>     }
>
> }
>
>
> Best Regards
> Hardy Henneberg
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/ProducerTemplate-sendBody-calls-toString-tp5722350.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: [email protected]
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Reply via email to