I am having a simple JSON as like below
{"Stagename":"Prospecting","OppName":"MM - Opportunity","CloseDate":"2022-10-08","Phone":"11111","Lastname":"M","Firstname":"M","Name":"MM"}
And trying to parse using the below class
public with sharing class ParseQuoteRequest {
public String Stagename; //Prospecting
public String OppName; //MM - Opportunity
public String CloseDate; //2022-10-08
public String Phone; //11111
public String Lastname; //M
public String Firstname; //M
public String Email; //[email protected]
public String Name; //MM
public static ParseQuoteRequest parse(String json){
return (ParseQuoteRequest) System.JSON.deserialize(json, ParseQuoteRequest.class);
}
}
and here is how I am calling from my Restresource like below
ParseQuoteRequest parsedRequest= ParseQuoteRequest.parse(req.requestBody.toString());
and I am getting this error
Malformed JSON: Expected '{' at the beginning of object
and I tried without desrialize also by this way
Map<String, Object> responseMap = (Map<String, Object>) JSON.deserializeUntyped(req.requestBody.toString());
then also getting the same error
and even tried like this
[{"Stagename":"Prospecting","OppName":"MM - Opportunity","CloseDate":"2022-10-08","Phone":"11111","Lastname":"M","Firstname":"M","Name":"MM"}]
public with sharing class ParseQuoteRequest {
public String Stagename; //Prospecting
public String OppName; //MM - Opportunity
public String CloseDate; //2022-10-08
public String Phone; //11111
public String Lastname; //M
public String Firstname; //M
public String Email; //[email protected]
public String Name; //MM
public static ParseQuoteRequest parse(String json){
return (List<ParseQuoteRequest>) System.JSON.deserialize(json, List<ParseQuoteRequest>.class);
}
}
Map<String, Object> request = new Map<String, Object>(); request.put('Stagename', 'Prospecting'); request.put('OppName', 'MM - Opportunity'); request.put('CloseDate', '2022-10-08'); request.put('Phone', '11111'); request.put('Lastname', 'M'); request.put('Firstname', 'F'); request.put('Email', '[email protected]'); ParseQuoteRequest req = ParseQuoteRequest.parse(JSON.serialize(request)); System.debug(req);
I tried this and works perfect for me0x7B
?