camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Stiborský <martin.stibor...@gmail.com>
Subject Re: Marshalling POJO class to JSON String formatted output
Date Mon, 26 Nov 2012 19:31:58 GMT
Sorry guys, lazy, tired me, not thinking before asking.
Of courser there is byte[] in the body...

for (Exchange receivedExchange : receivedExchanges) {
            String json = new String((byte[])
receivedExchange.getIn().getBody(), "UTF-8");
            System.out.println("JSON String: " + json);


On Mon, Nov 26, 2012 at 8:22 PM, Martin Stiborský <
martin.stiborsky@gmail.com> wrote:

> Hello guys,
> I'd like to ask you, I have a POJO classes, holding data representation of
> various kinds of data entities.
> Output of my Camel routes is JSON String returned to browser as response.
> I thought it would be easy to marshall POJO to JSON formatted String with
> Jackson, but I have something wrong there.
>
> Consider this code:
>
> public class PojoDemoRouteTest extends CamelTestSupport {
>
>     @Before
>     public void setup() throws Exception {
>         super.setUp();
>         context.addRoutes(new RouteBuilder() {
>             @Override
>             public void configure() throws Exception {
>                 from("direct:start")
>                 .marshal().json(JsonLibrary.Jackson)
>                 .to("mock:pojodemo");
>             }
>         });
>     }
>
>     @Test
>     public void basicPojoTest() throws InterruptedException {
>         MockEndpoint pojoMock = getMockEndpoint("mock:pojodemo");
>
>         JsonMarshallDemo demoPojo = new JsonMarshallDemo();
>         demoPojo.setBar("demo bar");
>         demoPojo.setFoo("demo foo");
>
>         template.sendBody("direct:start", demoPojo);
>
>         pojoMock.expectedMessageCount(1);
>
>         List<Exchange> receivedExchanges = pojoMock.getExchanges();
>         for (Exchange receivedExchange : receivedExchanges) {
>             System.out.println(String.format("Exchange getIn body: %s",
> receivedExchange.getIn().getBody()));
>             System.out.println(String.format("Exchange getOut body: %s",
> receivedExchange.getOut().getBody()));
>         }
>
>         pojoMock.assertIsSatisfied();
>     }
> }
>
> Why I don't see JSON String in the incomming message's body?
> When I debug this route, I can see that there is the JSON String, but not
> in the body, see:
> https://www.dropbox.com/sh/llvbflokwiheuby/X65PdXfwnJ/esb_pojo_marshall_debug.png
> Btw, it's String representation of the Message or what?
>
> --
> S pozdravem / Best regards
> Martin Stiborský
>
> Jabber: stibi@njs.netlab.cz
> Twitter: http://www.twitter.com/stibi
>
>


-- 
S pozdravem / Best regards
Martin Stiborský

Jabber: stibi@njs.netlab.cz
Twitter: http://www.twitter.com/stibi

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