13

I was trying to parse json to apex but i was getting

System.JSONException: Apex Type unsupported in JSON: Object

My apex code was

public class patdetils77
{

    //public String strBody{ get; set; }
    //public List<PatientDetail> lstopwrpr{get;set;}
    //public List<patient__c> patlistchld{ get; set;}
    //public List<patient__c> patlistSerlz{ get; set;}

    public DeviceInfo deviceInfo;
    public DispenseDetail dispenseDetail;
    public List<MedicationList> medicationList;
    public MiscellaneousDetail miscellaneousDetail;
    public PatientDetail patientDetail;
    public ProductDetail productDetail;
    public List<SmartVisitList> smartVisitList;
    public TrainingDetail trainingDetail;

       public patdetils77 ()
       {
            //patlistchld= new list<patient__c>();
           //patlistSerlz= new list<patient__c>();
       }


     public class PatientDetail {
        public String Address;
        public String BlueStarID;
        public Object CellphoneNumber;
        public String DOB;
        public String Email;
        public String Gender;
        public Object HomephoneNumber;
        public String HubCode;
        public Boolean IsMobileUser;
        public Boolean IsVTCompleted;
        public String Name;
        public Object SamleCode;
        public String WorkphoneNumber;
    }

    public class DispenseDetail {
        public Boolean IsRespondedToRefillPrompt;
        public String LastFillDate;
        public String LastUsageDate;
        public Integer NumOfRefillsLeft;
        public Integer NumOfRefillsPrescribed;
        public String PayerType;
        public String RespondedDate;
        public String RxExpirationDate;
        public String RxID;
    }

    public class TrainingDetail {
        public Object TrainerName;
        public String TrainingDate;
        public Object TrainingStatus;
    }

    public class ProductDetail {
        public Object HubStatus;
        public Object PharmacyStatus;
        public Object ProductStatus;
        public String RegistrationDate;
        public String SRFCompletedDate;
        public String SRFRecievedDate;
        public Object SRFStatus;
        public String TrainingCompletedDate;
        public Object TrainingStatus;
    }


    public class SmartVisitList {
        public String DeliverStatus;
        public String DeliveryDateTime;
        public String FaxNumber;
        public Integer NumOfSV;
        public String TriggeredDateTime;
    }

    public class MiscellaneousDetail {
        public String DateOfPTR;
        public Boolean IsAccountLocked;
        public Boolean IsPTR;
        public String LastMobileLogin;
        public String LastWebLogin;
        public Integer NumOfFailedLoginAttempts;
    }

    public class DeviceInfo {
        public Integer BuildID;
        public String MakeModel;
        public String MobileMake;
        public String Version;
    }

    public class MedicationList {
        public Integer Dosage;
        public Object Frequency;
        public String MedicationName;
        public String Strength;
    }


    public static patdetils77 parse(String json)
    {
        return (patdetils77)System.JSON.deserialize(json,patdetils77.class);
    }

    public PageReference gettingrecords()
     {
        HttpRequest req = new HttpRequest();
        req.setHeader('Content-Length', '0');
        req.setHeader('Content-Type', 'application/json');
        req.setEndpoint('https://dev1-dsm.testwd.com/CRMPOC/PatientProfileService.svc/GetPatientCompleteData');
        req.setMethod('POST');

        //Set patient ExternalID
        req.setBody('"S0110010021"');

        Http http = new Http();
        req.setTimeout(60000);
        system.debug('req***************'+req);
        HTTPResponse res = http.send(req);
        String strBody= res.getBody();
        system.debug('response------------'+strBody);


        patdetils77 objPant = parse(strBody);   

        system.debug('response---par---------'+objPant);




        /*

        for(PatientDetail objPRWrp:lstopwrpr)
        {
            patient__c objPant = new patient__c();

            objPant.BlueStarID__c = objPRWrp.BlueStarID;
            objPant.Name = objPRWrp.Name;
           // objPant.Hub_Code__c= objPRWrp.HubCode;
            objPant.Gender__c= objPRWrp.Gender;
            objPant.Mobile_User__c= objPRWrp.IsMobileUser;
           // objPant.SampleCode__c= objPRWrp.SamleCode;
            objPant.IsVTCompleted__c= objPRWrp.IsVTCompleted;
            objPant.Email__c= objPRWrp.Email;
            objPant.Address__c= objPRWrp.Address;
            patlistchld.add(objPant);
        }
                system.debug('patlist-----'+patlistchld);*/


        return null;
    } 




}

and my json was

{
   "deviceInfo":{
      "BuildID":87,
      "MakeModel":"Apple_iPhone",
      "MobileMake":"Apple_iPhone",
      "Version":"2.4"
   },
   "dispenseDetail":{
      "IsRespondedToRefillPrompt":true,
      "LastFillDate":"\/Date(1426046400000-0400)\/",
      "LastUsageDate":"\/Date(-62135578800000-0500)\/",
      "NumOfRefillsLeft":1,
      "NumOfRefillsPrescribed":1,
      "PayerType":"1",
      "RespondedDate":"\/Date(1426126039530-0400)\/",
      "RxExpirationDate":"\/Date(1455080400000-0500)\/",
      "RxID":"ngpX6g+iF05m2yuSN9KeN8s+kKCGQPdrOIC8b+zuSic="
   },
   "medicationList":[
      {
         "Dosage":15,
         "Frequency":null,
         "MedicationName":"Victoza 3-Pak",
         "Strength":"0.6 mg\/0.1 mL"
      },
      {
         "Dosage":1,
         "Frequency":"1",
         "MedicationName":"glipizide-metformin",
         "Strength":"2.5-250"
      },
      {
         "Dosage":1,
         "Frequency":null,
         "MedicationName":"Marinol",
         "Strength":"2.5"
      },
      {
         "Dosage":1,
         "Frequency":"1",
         "MedicationName":"DermaMed (aluminum hydroxide)",
         "Strength":""
      },
      {
         "Dosage":2,
         "Frequency":"1",
         "MedicationName":"metformin",
         "Strength":"500"
      },
      {
         "Dosage":3,
         "Frequency":"1",
         "MedicationName":"metformin",
         "Strength":"500"
      },
      {
         "Dosage":1,
         "Frequency":"1",
         "MedicationName":"metformin",
         "Strength":"500"
      },
      {
         "Dosage":2,
         "Frequency":"1,32",
         "MedicationName":"Acanya",
         "Strength":"1.2-2.5"
      },
      {
         "Dosage":2,
         "Frequency":"1",
         "MedicationName":"Effient",
         "Strength":"5"
      },
      {
         "Dosage":3,
         "Frequency":"1",
         "MedicationName":"Effient",
         "Strength":"5"
      },
      {
         "Dosage":2,
         "Frequency":null,
         "MedicationName":"magnesium oxide",
         "Strength":"400"
      },
      {
         "Dosage":2,
         "Frequency":"1",
         "MedicationName":"Amaryl",
         "Strength":"1"
      },
      {
         "Dosage":2,
         "Frequency":"1",
         "MedicationName":"aspirin",
         "Strength":"325"
      },
      {
         "Dosage":32,
         "Frequency":"1",
         "MedicationName":"Ayr Sinus Rinse",
         "Strength":""
      },
      {
         "Dosage":32,
         "Frequency":"1",
         "MedicationName":"Ayr Sinus Rinse",
         "Strength":""
      },
      {
         "Dosage":2,
         "Frequency":"1",
         "MedicationName":"Keralyt",
         "Strength":"3"
      },
      {
         "Dosage":15,
         "Frequency":"1",
         "MedicationName":"Apidra",
         "Strength":"100"
      },
      {
         "Dosage":15,
         "Frequency":"1",
         "MedicationName":"Apidra",
         "Strength":"100"
      },
      {
         "Dosage":15,
         "Frequency":"1",
         "MedicationName":"Apidra",
         "Strength":"100"
      },
      {
         "Dosage":10.5,
         "Frequency":"1",
         "MedicationName":"Humalog",
         "Strength":"100"
      },
      {
         "Dosage":10.5,
         "Frequency":"1",
         "MedicationName":"Humalog",
         "Strength":"100"
      },
      {
         "Dosage":10.5,
         "Frequency":"1",
         "MedicationName":"Humalog",
         "Strength":"100"
      }
   ],
   "miscellaneousDetail":{
      "DateOfPTR":"\/Date(-62135578800000-0500)\/",
      "IsAccountLocked":false,
      "IsPTR":false,
      "LastMobileLogin":"\/Date(1426323602323-0400)\/",
      "LastWebLogin":"\/Date(1426764614690-0400)\/",
      "NumOfFailedLoginAttempts":0
   },
   "patientDetail":{
      "Address":"#1. WellDoc Software Pvt ltd . Brigade Software park - 1 Unit 501,5th floor,B Block,No 42, Banglore ",
      "BlueStarID":"S0110010021",
      "CellphoneNumber":null,
      "DOB":"\/Date(-62135578800000-0500)\/",
      "Email":"crm+hubpat1@welldocinc.com",
      "Gender":"M",
      "HomephoneNumber":null,
      "HubCode":"S0110010021",
      "IsMobileUser":false,
      "IsVTCompleted":true,
      "Name":"FirstName1 LastName1",
      "SamleCode":null,
      "WorkphoneNumber":"9876543211"
   },
   "productDetail":{
      "HubStatus":null,
      "PharmacyStatus":null,
      "ProductStatus":null,
      "RegistrationDate":"\/Date(-62135578800000-0500)\/",
      "SRFCompletedDate":"\/Date(-62135578800000-0500)\/",
      "SRFRecievedDate":"\/Date(-62135578800000-0500)\/",
      "SRFStatus":null,
      "TrainingCompletedDate":"\/Date(-62135578800000-0500)\/",
      "TrainingStatus":null
   },
   "smartVisitList":[
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1378135864987-0400)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(-62135578800000-0500)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1378342865663-0400)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(-62135578800000-0500)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1380297673573-0400)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(-62135578800000-0500)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1380756857163-0400)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(-62135578800000-0500)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1382094075263-0400)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(-62135578800000-0500)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1382106677580-0400)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(-62135578800000-0500)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1382958065347-0400)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(-62135578800000-0500)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1382968864730-0400)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(-62135578800000-0500)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1393283482053-0500)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(1378324800000-0400)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1393296082523-0500)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(1380279780000-0400)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1393290682680-0500)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(1380739800000-0400)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1393288882960-0500)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(1382110840343-0400)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1393292483040-0500)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(1382090346343-0400)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1393285284500-0500)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(1382975180957-0400)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1393287083297-0500)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(1382986463627-0400)\/"
      },
      {
         "DeliverStatus":"3",
         "DeliveryDateTime":"\/Date(1409395687970-0400)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(1409379360000-0400)\/"
      },
      {
         "DeliverStatus":"4",
         "DeliveryDateTime":"\/Date(1421914133400-0500)\/",
         "FaxNumber":"14436923099",
         "NumOfSV":17,
         "TriggeredDateTime":"\/Date(1421868600000-0500)\/"
      }
   ],
   "trainingDetail":{
      "TrainerName":null,
      "TrainingDate":"\/Date(-62135578800000-0500)\/",
      "TrainingStatus":null
   }
}

Can anyone explain me regarding this issue, as i am completely new to salesfroce.

Any help is highly appreciated, thanks in advance.

24

The Salesforce JSON.deserialize(String, Type) method cannot deserialize from JSON into generic Object, or into objects with generic Object fields, it can only deserialize into concrete types with fields that have concrete type.

Everywhere the you have defined your field types as Object, e.g. public Object CellphoneNumber, you need to replace Object with the appropriate data type, i.e. String, Integer, etc.

Once you have replaced all of the Object fields in your data structures you should be able to deserialize your JSON into them successfully.

PS. It looks like you've used JSON2Apex to generate this. The reason the types of these fields are Object and not the correct types is because their values are null. JSON2Apex doesn't guess what type a null object should be (and rightly so), which is why it has used Object for these types.

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.