You need to sign in to do that
Don't have an account?

Need help in deserializing JSON list of input to my weservice
Web Service :
@RestResource(urlMapping='/UsageInput/')
global class APTS_UsageInputWS {
@HttpPost
global static void loadUsageInputs ()
{
RestRequest req =RestContext.request;
Blob body = req.requestBody;
String requestString = body.toString();
APTS_UsageInputWrapper inputList = (APTS_UsageInputWrapper)JSON.deserialize(requestString,APTS_UsageInputWrapper.class);
List<EQ_TempSSP1Data__c> tempData = new List<EQ_TempSSP1Data__c>();
system.debug('***1');
system.debug('%%%inputList');
if(inputList.ValidateOnly)
{
validateData(inputList);
}
else
{
delete [select id from EQ_TempSSP1Data__c];
Integer counter = 1;
for(APTS_UsageInputWrapperData record : inputList.data)
{
tempData.add(new EQ_TempSSP1Data__c(EQ_WorkId__c = inputList.EQ_WorkId,
EQ_SourceSystem__c = record.EQ_SourceSystem,
EQ_IssueNumber__c = record.EQ_IssueNumber,
EQ_ServiceCode__c = record.EQ_ServiceCode,
EQ_Quantity__c = record.EQ_Quantity,
EQ_QuantityID__c = record.EQ_QuantityID,
EQ_RecordKey__c = record.EQ_RecordKey,
EQ_LoadMonth__c = Date.newInstance(Integer.valueOf(record.EQ_LoadMonth.left(4)), Integer.valueOf(record.EQ_LoadMonth.subString(4,5)), Integer.valueOf(record.EQ_LoadMonth.subString(6,7))),
Name = counter + '-' + record.EQ_LoadMonth + '-' + record.EQ_IssueNumber));
counter++;
}
insert tempData;
system.debug('validation called%%%%');
validateData(inputList);
}
}
JSON input:
{
"EQ_Count":1,
"EQ_WorkId":"B-080319-4",
"ValidateOnly":False,
"Data":
[{"EQ_RecordKey":"ab3ff95a-42cc-4778-888d-e1f4c4beb78d",
"EQ_LoadMonth":"20190101",
"EQ_Quantity":32116,
"EQ_ServiceCode":"trsactmata",
"EQ_IssueNumber":"NW22",
"EQ_SourceSystem":"SSP1",
"EQ_QuantityID":"4737301"
},
{"EQ_RecordKey":"ab3ff95a-42cc-4778-888d-e1f4c4beb78d",
"EQ_LoadMonth":"20190101",
"EQ_Quantity":32116,
"EQ_ServiceCode":"trsactmata",
"EQ_IssueNumber":"NW22",
"EQ_SourceSystem":"SSP1",
"EQ_QuantityID":"4737301"
}]
}
While calling service from workbecnh getting error:
APEX_ERROR
message: System.JSONException: Unexpected character ('F' (code 70)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:4, column:18] Class.System.JSON.deserialize: line 15, column 1 Class.APTS_UsageInputWS.loadUsageInputs: line 14, column 1
global class APTS_UsageInputWrapper {
public String EQ_WorkId { get; set; }
public Integer EQ_Count { get; set; }
public Boolean ValidateOnly { get; set; }
public List<APTS_UsageInputWrapperData> data { get; set; }
}
You can create below class -
And use below line in your class to parse your json -
Let me know in case of any issue.
Regards,
Parmanand Pathak.