I am trying to wrap a request body from callin request which has a variable but values can be different data types.
Example request body 1 :
{
RecordId:"cncjdn"
}
Example request body 2 :
{
RecordId:"['cncjdn','dccwxass']"
}
In the above example request bodies, I have same key but values are of different datatype. I should be able to accept single RecordId or List of RecordId in the same variable. I cannot have separate variables for String and List in request body
In RestResource, I have wrapper class to which the request body will get de-serialized and assigned
public class RequestWrapper{
public String RecordId;
}
RequestWrapper w = (RequestWrapper)JSON.deserialize(req.requestBody.toString(),RequestWrapper.class);
The JSON.deserialize works only when Request body has String type data. How can I determine the datatype and map it to a variable having relevant datatype ?