camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bhuvan Gupta <bhuva...@gmail.com>
Subject Re: why adding a processor after unmarshaling in apache camel throw nullpointer
Date Sun, 11 Oct 2015 10:27:19 GMT
It worked once i changes to
             unmarshal().json(JsonLibrary.Gson, MyTest.class)

So basically while unmarshalling we have to provide the Type to convert to,
we just cant except it to change json string to a type specified in
getBody(..) method..   this is the reason... . right ?

I will update the stackoverflow once i get the correct explaination.

Thanks
Bhuvan

On Sun, Oct 11, 2015 at 3:46 PM, Bhuvan Gupta <bhuvangu@gmail.com> wrote:

> I changed the processor code to
>                  Object body = exchange.getIn().getBody();
> System.out.println("class: "+body.getClass());
> System.out.println("as string:" + body);
>
> and it printed :
>
> class: class com.google.gson.internal.LinkedTreeMap
> as string:{a=this is a, b=this is b, c={}}
>
> What is happening... not able to create a mind map of what is happening.
>
> Cheers
> Bhuvan
>
> On Sun, Oct 11, 2015 at 8:21 AM, Andrew Block <andy.block@gmail.com>
> wrote:
>
>> In your processor, since you are requesting the object contained in the
>> message body as a particular type, it is possible for the value to be null
>> if that is not the type that is actually on the body. Would you be able to
>> verify the object type after the unmarshall.? You can do this in your
>> processor by getting the Object on the message without a type
>> (message.getIn().getBody() and checking the type.
>>
>> - Andy
>>
>>
>> --
>> Andrew Block
>>
>> On October 10, 2015 at 3:46:52 PM, Bhuvan Gupta (bhuvangu@gmail.com)
>> wrote:
>>
>> Hello,
>>
>> I setup the camel routes shown below:
>> In stage folder i can see message getting marshal properly into a json.
>> but while un-marshaling on this line body.setA("modified A");
>> i get a null pointer exception basically body is null.. *Why* ?
>>
>> StackOverflow question link:
>>
>> http://stackoverflow.com/questions/33058563/adding-a-processor-after-unmarshaling-in-apache-camel
>>
>> from("direct:stage").marshal().json(JsonLibrary.Gson).to("file://stage");
>>
>> from("file://stage").unmarshal().json(JsonLibrary.Gson).process(new
>> Processor() {
>> @Override
>> public void process(Exchange exchange) throws Exception {
>> MyTest body = exchange.getIn().getBody(MyTest.class);
>> body.setA("modified A");
>> }}).to("direct:b");
>>
>>
>

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