I am calling a web method in asmx web service from my android app and that Method accepts a json object. When I debug my app it gives me following exception "Cannot Serialize 1001.10"( its my one of class variables value ). here below I am sending data by hard coding values( for test purposes)
Item itm=new Item();
ItemType itype=new ItemType();
itm.Description="Good Product";
itm.BarcodeNumber="1234";
itm.Depreciation=(float) 100.56;
itm.AgencyId=1;
itm.ItemCode="Android";
itm.ItemValue=(float) 9999.99;
itm.PurDate=new Date(0); //Date I am sending here...
itm.PurValue=(float) 1001.10;
itype.Itemname="Android App";
itype.Make="Android Developers";
itype.Model="2013 Model";
itype.Year=new Date(0);
itm.iType=itype;
I am getting exception as "Cannont serialize 1001.01" after itm.PurValue (caught exception when I debug my app)
I thought it is due to date format but since my Web service accepts json object I thought the error could be format of object I am sending.
To convert a java object to json object I have added the gson.jar file into my java build path - -libraries .
and use Gson to convert java object to json string and passed that json string to web service.
When I run the app it aborts and says " Unfortunately, My App stopped working"
Here is my code which I use for converting java object to json string.
Gson gson = new Gson(); //Exception Occurred at this point when control comes here it is giving as Invocation Target Exception
String json=gson.toJson(itm);
p.setName("ThisItem");
p.setValue(json);
p.setType(String.class);
request.addProperty(p);
and the remaining code is common... but for reference I am pasting that code too here.
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.dotNet=true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidTSE=new HttpTransportSE(URL);
try
{
androidTSE.call(Soap_Action, envelope);
SoapObject response=(SoapObject) envelope.getResponse();
return response.toString();
}
catch(Exception ex)
{
return ex.toString();
}
I am getting an exception as Invocation Target Exception when I debug my app with above gson code inculded.
what may be the problem? Is the date format I am using in my object or the format of converting java object to gson object?
Finally I like to say that I want to send an json object to my asmx web service. How can I solve this problem. Please any one could share any ideas. I am struggling for this error for 7 hours.
Thanks in advance Ganesh