camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Block <>
Subject Re: why adding a processor after unmarshaling in apache camel throw nullpointer
Date Sun, 11 Oct 2015 16:42:37 GMT
The Gson library will unmarshal an object to specified type if it is provided, otherwise it
will return a LinkedHashMap of the objects that it was able to unmarshal. The getBody() in
the processor has no direct connection to the previously unmarshaled object the object type
must be specified in the unmarshal component. 

- Andy

Andrew Block

On October 11, 2015 at 5:27:19 AM, Bhuvan Gupta ( wrote:

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.


On Sun, Oct 11, 2015 at 3:46 PM, Bhuvan Gupta <> 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
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.


On Sun, Oct 11, 2015 at 8:21 AM, Andrew Block <> 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 ( wrote:


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:


Processor() {
public void process(Exchange exchange) throws Exception {
MyTest body = exchange.getIn().getBody(MyTest.class);
body.setA("modified A");

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