Return-Path: X-Original-To: apmail-camel-users-archive@www.apache.org Delivered-To: apmail-camel-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 36F8F18D74 for ; Sun, 11 Oct 2015 16:42:51 +0000 (UTC) Received: (qmail 37321 invoked by uid 500); 11 Oct 2015 16:42:50 -0000 Delivered-To: apmail-camel-users-archive@camel.apache.org Received: (qmail 37269 invoked by uid 500); 11 Oct 2015 16:42:50 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Received: (qmail 37256 invoked by uid 99); 11 Oct 2015 16:42:50 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 Oct 2015 16:42:50 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id A16B51A094E for ; Sun, 11 Oct 2015 16:42:49 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.899 X-Spam-Level: *** X-Spam-Status: No, score=3.899 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_REPLY=1, HTML_MESSAGE=3, RCVD_IN_MSPIKE_H2=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id sTajVRJF3rZk for ; Sun, 11 Oct 2015 16:42:41 +0000 (UTC) Received: from mail-io0-f175.google.com (mail-io0-f175.google.com [209.85.223.175]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTPS id 9782B204D9 for ; Sun, 11 Oct 2015 16:42:40 +0000 (UTC) Received: by iodv82 with SMTP id v82so32605918iod.0 for ; Sun, 11 Oct 2015 09:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:message-id:in-reply-to:references:subject :mime-version:content-type; bh=czm0aggqPLH7iTKf7Rgg38bFglb5PNuDP1g5lqaN/Kw=; b=FFBydqPfVYHvFiictRGWD545+EagnOgK5z0wsNn7y1ghDYvT31oi76/Ce5ue6Am/uo 21vLoKFhgzRFXBwYWyQ5DRGb4uIDL6eu6pFxPVt78Nln3WY7jU+zzQ4BoH1ZaSkLkPZI Oj4iu/t66SCOPQgVnjAMJsJIHEL5nWTBby9O1fT5EuH9NWiAwv5l96srTfvDe0YFVHZo RZpLONyjWlmjSYZKp00HeHuP5KwqMjLN42Pwmr8T9Fuz8WtxdNOwqhVlkSEkj8nxXjwx /fTBG1POl03KJsDryyiOKn75bd8wZ5K8dMllJhkMNVAOaECTM4zCnocVOpKvKbh3Boai sJRg== X-Received: by 10.107.162.81 with SMTP id l78mr23305804ioe.176.1444581759561; Sun, 11 Oct 2015 09:42:39 -0700 (PDT) Received: from Andrews-MacBook-Pro.local (205-178-77-85.c3-0.nwb-ubr1.chi-nwb.il.cable.rcn.com. [205.178.77.85]) by smtp.gmail.com with ESMTPSA id 67sm5417171iog.34.2015.10.11.09.42.38 (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 11 Oct 2015 09:42:39 -0700 (PDT) Date: Sun, 11 Oct 2015 11:42:37 -0500 From: Andrew Block To: Bhuvan Gupta Cc: users@camel.apache.org Message-ID: In-Reply-To: References: Subject: Re: why adding a processor after unmarshaling in apache camel throw nullpointer X-Mailer: Airmail (249) MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="561a917d_5bd062c2_7fa" --561a917d_5bd062c2_7fa Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The Gson library will unmarshal an object to specified type if it is prov= ided, otherwise it will return a LinkedHashMap of the objects that it was= able to unmarshal. The getBody() in the processor has no direct connecti= on to the previously unmarshaled object the object type must be specified= in the unmarshal component.=C2=A0 - Andy --=C2=A0 Andrew Block On October 11, 2015 at 5:27:19 AM, Bhuvan Gupta (bhuvangu=40gmail.com) wr= ote: It worked once i changes to=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0unmarshal().json(JsonLibr= ary.Gson, MyTest.class) So basically while unmarshalling we have to provide the Type to convert t= o, we just cant except it to change json string to a type specified in ge= tBody(..) method.. =C2=A0 this is the reason... . right =3F I will update the stackoverflow once i get the correct explaination. Thanks Bhuvan On Sun, Oct 11, 2015 at 3:46 PM, Bhuvan Gupta wrot= e: I changed the processor code to=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Object body= =3D exchange.getIn().getBody(); System.out.println(=22class: =22+body.getClass());=C2=A0 System.out.println(=22as string:=22 + body); and it printed : class: class com.google.gson.internal.LinkedTreeMap as string:=7Ba=3Dthis is a, b=3Dthis is b, c=3D=7B=7D=7D 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 wr= ote: In your processor, since you are requesting the object contained in the m= essage 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.=3F You can do this in you= r processor by getting the Object on the message without a type (message.= getIn().getBody() and checking the type.=C2=A0 - Andy --=C2=A0 Andrew Block On October 10, 2015 at 3:46:52 PM, Bhuvan Gupta (bhuvangu=40gmail.com) wr= ote: 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(=22modified A=22); i get a null pointer exception basically body is null.. *Why* =3F StackOverflow question link: http://stackoverflow.com/questions/33058563/adding-a-processor-after-unma= rshaling-in-apache-camel from(=22direct:stage=22).marshal().json(JsonLibrary.Gson).to(=22file://st= age=22); from(=22file://stage=22).unmarshal().json(JsonLibrary.Gson).process(new Processor() =7B =40Override public void process(Exchange exchange) throws Exception =7B MyTest body =3D exchange.getIn().getBody(MyTest.class); body.setA(=22modified A=22); =7D=7D).to(=22direct:b=22); --561a917d_5bd062c2_7fa--