I am trying to get the status,# record processed etc details by hitting the bulk API endpoint - /services/async/39.0/job/75037000003BXtw/batch
In response I got the below JSON structure:
{"batchInfo":[{"apexProcessingTime":1993,"apiActiveProcessingTime":4765,"createdDate":"2017-07-26T23:51:29.000+0000","id":"751370000046EakAAE","jobId":"75037000003BXtwAAG","numberRecordsFailed":0,"numberRecordsProcessed":500,"state":"Completed","stateMessage":null,"systemModstamp":"2017-07-26T23:51:37.000+0000","totalProcessingTime":5447}]}
I used JSONtoApex tool to generate the required Class to parse the JSON:
public class BatchInfo {
public Integer apexProcessingTime;
public Integer apiActiveProcessingTime;
public String createdDate;
public String id;
public String jobId;
public Integer numberRecordsFailed;
public Integer numberRecordsProcessed;
public String state;
public Object stateMessage;
public String systemModstamp;
public Integer totalProcessingTime;
}
As usual I use the below code to desearialize the JSON file:
List<BatchInfo> respJson =(List<BatchInfo>)JSON.deserialize(res2.getbody() , List<BatchInfo>.class);
I get an error saying - System.JSONException: Malformed JSON: Expected '[' at the beginning of List/Set
On doing some research I found a link which could resolve this issue - Deserialize JSON Array With Integer Index , but I get some other error now when I try to desearlize using the code in the link:
Map<String,Object> jsonMap = (Map<String,Object>)JSON.deserializeUntyped(res2.getbody());
String jsonSubset = JSON.serialize(jsonMap.get('batchInfo'));
system.debug('JsonSubset======>' + jsonSubset); // [{"totalProcessingTime":5447,"systemModstamp":"2017-07-26T23:51:37.000+0000","stateMessage":null,"state":"Completed","numberRecordsProcessed":500,"numberRecordsFailed":0,"jobId":"75037000003BXtwAAG","id":"751370000046EakAAE","createdDate":"2017-07-26T23:51:29.000+0000","apiActiveProcessingTime":4765,"apexProcessingTime":1993}]
Map<String,Object> jsonSubsetMap = (Map<String, Object>)JSON.deserializeUntyped(jsonSubset); // get below error at this line
Error - System.TypeException: Invalid conversion from runtime type List<ANY> to Map<String,ANY>
Any suggestion? or Answer?