You need to sign in to do that
Don't have an account?
BHASKAR GANGULY
jason.deserialize is returning null
Hi All,
i am trying to parsing the below jason into my object.but while using the deserialize method its comming as Null.
not sure what i am missinh here.
Jason response :
{"invoiceList":[{"totalPrice":5.5,"statementDate":"2011-10-04T16:58:54.858Z","lineItems":[{"UnitPrice":1.0,"Quantity":5.0,"ProductName":"Pencil"},{"UnitPrice":0.5,"Quantity":1.0,"ProductName":"Eraser"}],"invoiceNumber":1},{"totalPrice":11.5,"statementDate":"2011-10-04T16:58:54.858Z","lineItems":[{"UnitPrice":6.0,"Quantity":1.0,"ProductName":"Notebook"},{"UnitPrice":2.5,"Quantity":1.0,"ProductName":"Ruler"},{"UnitPrice":1.5,"Quantity":2.0,"ProductName":"Pen"}],"invoiceNumber":2}]}
Wrapper class for data structure :
public class WrapperListinvoice {
public List<invoicelist> invoicepp;
public class invoicelist{
public double totalprice;
public DateTime Statementdate;
public list<Lineitems> sline;
public integer invoicenum;
}
public class Lineitems{
public double unitprice;
public double quantity;
public string productname;
}
}
calling class :
HttpRequest res= new HttpRequest();
res.setEndpoint('https://docsample.herokuapp.com/jsonSample');
res.setMethod('GET');
res.setHeader('Content-Type', 'application/json');
res.setHeader('Accept','application/json');
Http hes= new Http();
httpresponse repp=hes.send(res);
string s=repp.getBody();
integer status =repp.getStatusCode();
//list<responseBean> assp= new list<responseBean>();
WrapperListinvoice responseBean=(WrapperListinvoice) JSON.deserialize(s,WrapperListinvoice.class);
system.debug(responseBean);
Can somebody please help me to understand what i am missing here.
Thanks,
Bhaskar
i am trying to parsing the below jason into my object.but while using the deserialize method its comming as Null.
not sure what i am missinh here.
Jason response :
{"invoiceList":[{"totalPrice":5.5,"statementDate":"2011-10-04T16:58:54.858Z","lineItems":[{"UnitPrice":1.0,"Quantity":5.0,"ProductName":"Pencil"},{"UnitPrice":0.5,"Quantity":1.0,"ProductName":"Eraser"}],"invoiceNumber":1},{"totalPrice":11.5,"statementDate":"2011-10-04T16:58:54.858Z","lineItems":[{"UnitPrice":6.0,"Quantity":1.0,"ProductName":"Notebook"},{"UnitPrice":2.5,"Quantity":1.0,"ProductName":"Ruler"},{"UnitPrice":1.5,"Quantity":2.0,"ProductName":"Pen"}],"invoiceNumber":2}]}
Wrapper class for data structure :
public class WrapperListinvoice {
public List<invoicelist> invoicepp;
public class invoicelist{
public double totalprice;
public DateTime Statementdate;
public list<Lineitems> sline;
public integer invoicenum;
}
public class Lineitems{
public double unitprice;
public double quantity;
public string productname;
}
}
calling class :
HttpRequest res= new HttpRequest();
res.setEndpoint('https://docsample.herokuapp.com/jsonSample');
res.setMethod('GET');
res.setHeader('Content-Type', 'application/json');
res.setHeader('Accept','application/json');
Http hes= new Http();
httpresponse repp=hes.send(res);
string s=repp.getBody();
integer status =repp.getStatusCode();
//list<responseBean> assp= new list<responseBean>();
WrapperListinvoice responseBean=(WrapperListinvoice) JSON.deserialize(s,WrapperListinvoice.class);
system.debug(responseBean);
Can somebody please help me to understand what i am missing here.
Thanks,
Bhaskar
"UnitPrice":1.0 --> should be change like "UnitPrice":"1.0"
Use the deserializeUntyped as shown below
Use the below wrapper class