In order to make a @future(callout=true)
call, I'm serializing an HTTPRequest
object in order to send it to the @future method accepting a String jsonHttpRequest parameter.
Instance Method
HttpRequest request = new HttpRequest();
request.setEndpoint(someUrl);
// ... continue populating request
sendAsyncRequest(JSON.serialize(request));
Future Method
@future(callout=true)
private static void sendAsyncRequest(String jsonHttpRequest) {
HttpResponse response = new Http().send((HttpRequest)JSON.deserialize(jsonHttpRequest, HttpRequest.class));
}
But this code is giving me the following error:
System.JSONException: Apex Type unsupported in JSON: System.HttpRequest
Using JSON.deserializeStrict()
and JSON.deserializeUntyped()
hasn't worked for me either.
Any ideas here? I'm open to other approaches (thought about Queueable
but @future
is a more natural fit for the current use case)