i'm trying to convert the json response as sObject(Case).
but i'm little confusion to map external sys fields with sobject fields
this is my JSON response :
{"result":[{"short_description":"Can't read email","sys_id":"9c573169c611228700193229fff72400","incident_state":"7","urgency":"1","impact":"1","active":"false"}]}
this is what i have done :
res = http.send(req);
System.debug(res.getBody());
String jsonText =res.getBody();
Map<String, Object> cObjMap = (Map<String, Object>) JSON.deserializeUntyped(jsonText);
String cObjJson = JSON.serialize(cObjMap.get('Data'));
// Why again :
(Map<String, Object> cObjMapFurious = (Map<String, Object>) JSON.deserializeUntyped(cObjJson);
String cObjJsonDrunk = JSON.serialize(cObjMapFurious);
try
{
SObject customObject = (SObject)JSON.deserialize(cObjJsonDrunk, Sobject.class);
System.debug(' Accomplished: '+customObject);
}
catch(Exception ex)
{
System.debug(' @@@@@ Don\'t visible '+ex.getMessage());
}
This is my wrapper class, how should I map with case?
global class Deserialization{
public String short_description;
public String sys_id;
public String incident_state;
public String urgency;
public String impact;
public String active;
global Deserialization(String short_description1,String sys_id1,String incident_state1,String urgency1,String impact1,String active1){
short_description = short_description1;
sys_id = sys_id1;
incident_state = incident_state1;
urgency = urgency1;
impact = impact1;
active = active1;
}
}
Best Answer
You can delete you answer, but you need to build the object that you are expecting.. I use Json to Apex, I take that as a starting point, I don't build it exactly how it tells me, I have quirks I like to do. But this will work for you. I'll leave it in this format so you can execute anon it..
This will return an object looking like this.. You will then need to loop through this object and build whatever else you need out of it