function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lavanya mulpurilavanya mulpuri 

Cannot deserialize instance of <unknown> from null value null or request may be missing a required field

Hi All,

I'm unable to deserialize a string even when the value is not null. Here is my code snippet.

​public static List<ObjectA> processSelected(String constr) {
        system.debug('constr===>'+constr);  //getting value in this
        List<dupeContact> conList = (List<dupeContact>)JSON.deserialize(constr, List<dupeContact>.class);
        system.debug('dupeContact====>'+conList);     
        List<ObjectA> selectedContacts = new List<ObjectA>();
        if (conList != null && conList.size() >0) { 
            for (dupeContact  cCon : conList) {
                if (cCon.selected == true) {
                    selectedContacts.add(cCon.con);
                }
            }
        }

Thanks in Advance  :)
Aman MalikAman Malik
Hi,
Can you post the 'constr' string value.

Thanks,
Aman
lavanya mulpurilavanya mulpuri
This is the value that's getting generating in constr. It's a type Wrapper class, name dupeContact


11:10:35:003 USER_DEBUG [927]|DEBUG|constr===>[{"con":{"Name":"1 Lead Test best","First_Name__c":"1 Lead Test","Last_Name__c":"best","Id":"a00c0000006dIlYAAU","OwnerId":"005c0000003konIAAQ","Phone__c":"1234567890","Evening_Phone__c":"(963) 258-7410","Cell_Phone__c":"(014) 785-2369","Email__c":"test@best.com","Work_Email__c":"testsecondary@best.com","Owner":{"Name":"TestApps","Id":"005c0000003konIAAQ"}},"selected":true},{"con":{"Name":"1 Lead Test 2 best","First_Name__c":"1 Lead Test 2","Last_Name__c":"best","Id":"a00c0000006dIlJAAU","OwnerId":"005c0000003konIAAQ","Owner":{"Name":"TestApps","Id":"005c0000003konIAAQ"}},"selected":true},{"con":{"Name":"1 Lead Test 2 best","First_Name__c":"1 Lead Test 2","Last_Name__c":"best","Id":"a00c0000006dIkzAAE","OwnerId":"005c0000003konIAAQ","Owner":{"Name":"TestApps","Id":"005c0000003konIAAQ"}},"selected":false},{"con":{"Name":"1 Lead Test best","First_Name__c":"1 Lead Test","Last_Name__c":"best","Id":"a00c0000006dIkuAAE","OwnerId":"005c0000003konIAAQ","Owner":{"Name":"TestApps","Id":"005c0000003konIAAQ"}},"selected":false},{"con":{"Name":"1 Lead Test best","First_Name__c":"1 Lead Test","Last_Name__c":"best","Id":"a00c0000006dLmzAAE","OwnerId":"005c0000003konIAAQ","Email__c":"test@best.com","Work_Email__c":"testsecondary@best.com","Owner":{"Name":"TestApps","Id":"005c0000003konIAAQ"}},"selected":false}]
Suraj TripathiSuraj Tripathi

Hi lavanya mulpuri,

Please try this for deserialization. Hope it will help you.

List<dupeContact> conList = (List<dupeContact>) JSON.deserializeUntyped(constr);

Mark as a best if it will help you.

Regards,

Suraj

lavanya mulpurilavanya mulpuri
Hi Suraj,

It's throwing a run time error "FATAL_ERROR System.TypeException: Invalid conversion from runtime type List<ANY> to List<FindDupeLeads_Lightning.dupeContact>"
Please let me know if there's any other alternative.

Thanks!
v varaprasadv varaprasad
Hi Lavanya,

Please use below code it may help you.

List<dupeContact> conList = (List<dupeContact>) JSON.deserializeUntyped(List<dupeContact>,dupeContact.class);

List<dupeContact> conList = (List<dupeContact>) JSON.deserialize(List<dupeContact>,dupeContact.class);

List<dupeContact> conList = (List<dupeContact>) JSON.deserializeStrict(List<dupeContact>,dupeContact.class);


Please let me know in case of any other assistance.


Thanks
Varaprasad
lavanya mulpurilavanya mulpuri
Hi Varaprasad, 

Can you tell me where exactly should I pass the constr, which contains the JSON String. And the syntaxes you've mentioned are throwing multiple compile time errors.

Thanks!
Veena Sundara-HeraguVeena Sundara-Heragu
Hi Lavanya,
Did you get this resolved ? I have the same error.