I am writing an Apex Rest Service with the POST
Method. For that, I have written an apex class wrapper for the request. Like below.
global class RestRequestWrapper {
global String eId;
global Decimal salary;
global String email;
global Date joiningDate;
}
Below is the simplified version of my doPost
method. Where I am passing an instance of RestRequestWrapper
class a parameter.
@RestResource(urlMapping='/ExampleRestService/*')
global class ApexRestServiceExample {
@HttpPost
global static String doPost(RestRequestWrapper requestData) {
System.debug(requestData);
return 'success';
}
}
When I am calling this API, from workbench with the below JSON body.
{
"eId": "asasdasdasd",
"salary": 122233,
"email": "[email protected]"
}
Returns this response.
[
{
"message": "Unexpected parameter encountered during deserialization: eId at [line:2, column:10]",
"errorCode": "JSON_PARSER_ERROR"
}
]
I don't run into any errors if I pass an empty JSON {}
.
However, the JSON I am able to parse when fetched from the Request Body.
I am not getting what I am doing wrong here. What is the difference when it is fetched from RestContext.request.requestBody.toString()
?