0

On recieving a response from the external system, I used Json2Apex to create the apex class viz., AuthCalloutPostWrapper

When I use the following debug

 System.debug('##res.getBody##'+res.getBody());

I get a proper JSON response.

requestbody##{ "short_description" : "test", "caller_id" : "00001xx3", "priority" : "High", }

But when I used this...

 String responseBody = res.getBody();
 AuthCalloutPostWrapper JSONDetails=(AuthCalloutPostWrapper) System.JSON.deserialize(responseBody, AuthCalloutPostWrapper.class);
 System.debug('##JSONDetails##'+JSONDetails);

JSONDetails return me null in all the parameters.

JSONDetails##AuthCalloutPostWrapper:[caller_id=null, priority=null, short_description=null]

UPDATE: Also using..

  AuthCalloutPostWrapper  myJSON = AuthCalloutPostWrapper.parse(responseBody);

returns me null in all the parameters.

UPDATE: For the code below:

 HTTPResponse res = http.send(req);
 System.debug('##res.getBody##'+res.getBody());

Here's the full response:

res.getBody##{"result":{"location":"","expected_start":"","reopen_count":"0","close_notes":"","impact":"1","urgency":"1","sys_domain":{"link":"xxx/table/sys/global","value":"global"},"description":"","group_list":"","priority":"1","delivery_plan":"","sys_mod_count":"0","work_notes_list":"","follow_up":"","closed_at":"","sla_due":"","delivery_task":"","sys_updated_on":"2015-12-17 01:49:04","parent":"","work_end":"","number":"xxx123","closed_by":"","work_start":"","calendar_stc":"","business_duration":"","category":"inquiry","incident_state":"1","activity_due":"","correlation_display":"","company":"","active":"true","due_date":"","assignment_group":"","caller_id":{"link":abc/api/now/table/sys_user/ababd","value":"ababd"},"knowledge":"false","made_sla":"true","comments_and_work_notes":"","parent_incident":"","state":"1","user_input":"","approval_set":"","reassignment_count":"0","rfc":"","u_record_url":"","child_incidents":"0","opened_at":"2015-12-17 07:49:04","short_description":"test as subject","order":"","sys_updated_by":"admin","resolved_by":"","notify":"1","upon_reject":"cancel","approval_history":"","problem_id":"","work_notes":"","calendar_duration":"","close_code":"","sys_id":"xxxx","approval":"not requested","caused_by":"","severity":"3","sys_created_by":"User1","resolved_at":"","assigned_to":"","bus_abc":"","sys_domain_path":"/","cmdb_ci":"","opened_by":{"link":"xxx/api/now/table/sys_user/abc","value":"abadw"},"subcategory":"","sys_class_name":"incident","watch_list":"","time_worked":"","contact_type":"phone","escalation":"0","comments":"test"}}

Let me know where I might have gone wrong. Thanks in advance!

1

Your wrapper class should be as follows

public class AuthCalloutPostWrapper{
    public String short_description;    //test
    public String caller_id;    //xxxx
    public String priority; //High
    public static AuthCalloutPostWrapper parse(String json){
        return (AuthCalloutPostWrapper) System.JSON.deserialize(json, AuthCalloutPostWrapper.class);
    }

}

and you can call this in following way

String responseBody = res.getBody();
 AuthCalloutPostWrapper JSONDetails=AuthCalloutPostWrapper.parse(responseBody);
 System.debug('##JSONDetails##'+JSONDetails);
  • Hello once again! Ditto but doesn't seem to work! – MnZ Nov 16 '15 at 16:47
  • I have tested this and it is working fine. It seems like you have problem with your json. I can see two times caller_id, remove last one. json should be like this { "short_description" : "test","priority" : "High", "caller_id" : "xxxx" } – Himanshu Nov 16 '15 at 17:07
  • got the issue ? – Himanshu Nov 16 '15 at 17:27
  • Hey I corrected and I have only 1 caller_id now. But still I get null values. Let me post the JSON response as update in my question – MnZ Nov 17 '15 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.