This post explain how to 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 = (Information) JSON.deserialize(res, Information.class);
system.debug(rapper);
}
public class Information{
@AuraEnabled public List<Info> Info {get;set;}
}
public class Info
{
@AuraEnabled public String name{get;set;}
@AuraEnabled public String currency1{get;set;}
}
}
Thanks,
Lovesalesforceyes
No comments:
Post a Comment