BACKGROUND
I need to generate the below JSON data:
JSON
{
"Type": "ACCPAYCREDIT",
"Status": "AUTHORISED",
"Contact": {
"ContactID": "eaa28f49-6028-4b6e-bb12-d8f6278073fc"
},
"Date": "2009-03-29",
"LineAmountTypes": "Exclusive",
"LineItems": [
{
"Description": "MacBook - White",
"Quantity": 1.0000,
"UnitAmount": 1995.00,
"AccountCode": "720"
}
]
}
So I've created the below Apex class
Apex Class
public class XeroCreditNote {
public String Type;
public String Status;
public XeroContact Contact;
public Date Date; // <------- THIS LINE ERRORS
public String LineAmountTypes;
public LineItem[] LineItems;
public class LineItem {
public String Description;
public Integer Quantity;
public Decimal UnitAmount;
public String AccountCode;
}
}
But the line public Date Date;
give me an error:
Identifier name is reserved: Date
The class is serialsied like this:
return (List<XeroCreditNote>) JSON.deserialize(jsonSerialized, List<XeroCreditNote>.class);
QUESTION
I would like to be able to set the Apex property name to something that isn't reserved but make sure the correct property name is used when the object is serialized.
How can I do this with Apex?