You need to sign in to do that
Don't have an account?
wsmith
RestResource with @HttpPost method with parameters, RestContext.request.requestBody is null
Using a RestResource with a @HttpPost method with parameters, the RestContext.request.requestBody is null compared to a methods without parameters. Is this a bug?
1) Without parameters, RestContext.request.requestBody is not null
Using Workbench: REST Explorer with JSON {"testItRec" : {"Error" : "An error", "IsSuccess" : false}}
Output:
...
USER_DEBUG|[24]|ERROR|jsonStr ===> {
"testItRec" : {
"Error" : "An error",
"IsSuccess" : false
}
}
...
2) With parameter, RestContext.request.requestBody is null
Using Workbench Rest Explorer with JSON {"testItRec" : {"Error" : "An error", "IsSuccess" : false}}
Output:
...
USER_DEBUG|[34]|ERROR|jsonStr ===> null
...
1) Without parameters, RestContext.request.requestBody is not null
@RestResource(urlMapping='/TestRestA/*') global class WS_TestRestA { global class TestIt { global String Error; global Boolean IsSuccess; } @HttpPost global static void createTestIt() { String jsonStr = null; if (null != RestContext.request.requestBody) { jsonStr = RestContext.request.requestBody.toString(); } System.debug(LoggingLevel.ERROR, 'jsonStr ===> ' + jsonStr); } }
Using Workbench: REST Explorer with JSON {"testItRec" : {"Error" : "An error", "IsSuccess" : false}}
Output:
...
USER_DEBUG|[24]|ERROR|jsonStr ===> {
"testItRec" : {
"Error" : "An error",
"IsSuccess" : false
}
}
...
2) With parameter, RestContext.request.requestBody is null
@RestResource(urlMapping='/TestRestA/*') global class WS_TestRestA { global class TestIt { global String Error; global Boolean IsSuccess; } @HttpPost global static void createTestIt(TestIt testItRec) { String jsonStr = null; if (null != RestContext.request.requestBody) { jsonStr = RestContext.request.requestBody.toString(); } System.debug(LoggingLevel.ERROR, 'jsonStr ===> ' + jsonStr); } }
Using Workbench Rest Explorer with JSON {"testItRec" : {"Error" : "An error", "IsSuccess" : false}}
Output:
...
USER_DEBUG|[34]|ERROR|jsonStr ===> null
...
"If the Apex method has no parameters, then Apex REST copies the HTTP request body into the RestRequest.requestBody property. If there are parameters, then Apex REST attempts to deserialize the data into those parameters and the data won't be deserialized into the RestRequest.requestBody property."
{
"Error" : "An error",
"IsSuccess" : false
}