You need to sign in to do that
Don't have an account?
JSON deserializing question
We need to call a service which returns json content. The response contains salesforce reserved keywords as element/attribute names. when I try to create the binding class I am getting a compile error as date and currency are reserved keywords.
I know we can use deserializeUntyped or ask the service provider to make the change but trying to see if there is a clean and easy way to handle on salesforce side with binding class in place.
Below is a sample which is throwing error, Please let me know if anyone has any workarounds for this.
{
"creditCard": {
"id": "string",
"firstName": "string",
"lastName": "string",
"cardNo": "string",
"cvv": "string",
"date": "string",
"currency": "string"
}
}
Binding class which gives compile error
public class CreditCardSample{
public CreditCard creditCard;
public class CreditCard {
public String id;
public String firstName;
public String lastName;
public String cardNo;
public String cvv;
public String date;
public String currency;
}
}
You have to use one of the generic json parsers instead of stronly typed classes. See code in the page.
If you are getting http response in Json format you should parse it through JSONParser class.
For example:
JSONParser parser = JSON.createParser(RestContext.request.requestBody.toString());