Saturday, December 18, 2021

How to handle Identifier name is reserved error in apex json response

This post explain how to handle Identifier name is reserved error in apex json response.


Handle Identifier name is reserved error in apex json response

To handle the reserved identifier name in apex you have to replace the reserved variable with some non reserved variable and also change the wrapper variables accordingly. Refer the following code:


HandleReserveIdentifier.apx:

public class HandleReserveIdentifier {
    public static void handler(){
        String res = '{"Info": [{"name": "carry","currency": "INR"},{"name": "max","currency": "CLPs"}]}';
        res = res.replace('currency','currency1'); // Replace reserved identifier with some non-reserved identifier
        Information rapper = new Information();
        rapper = (InformationJSON.deserialize(res, Information.class);
        system.debug(rapper);
    }
    
     public class Information{
        @AuraEnabled public List<InfoInfo {get;set;}
    }
        public class Info
        {
            @AuraEnabled public String name{get;set;}
            @AuraEnabled public String currency1{get;set;}
        }
}


Thanks, 
Lovesalesforceyes

No comments:

Post a Comment

Get selected radio button value in LWC

This post explains how to get selected radio button in LWC. Below is demo of output : To use the radio button in LWC you have to use the  li...