Before I go ahead and describe my issue, I have looked at a resolution as described below and does not seem to help in my case. is that possible to pass(POST) below JSON to REST endpoint?
So, I have a json object - really long, but let me shorten it as below:
{
"jsonStr": {
"myId": "1010101010101010",
"randomInt": 1,
"arrayOfObjs": [{
"objid": "string_data",
"mytimestamp": "xxxxxxxxxxxx",
"externalRefId": "1010101010101010",
"myMap": {
"key1": "val1",
"key2": "val2"
}
}]
}
}
I pass this to the post method of my rest resource. The param name is String jsonStr similar to below:
@HttpPost
global static String doPost(String jsonStr) {
An error with status code 400 BAD REQUEST is sent by the salesforce endpoint with the following description:
{
"message": "Unexpected parameter encountered during deserialization: myId at [line:1, column:XX]",
"errorCode": "JSON_PARSER_ERROR"
}
I have also tried it without the outer JSON as in below:
{
"myId": "1010101010101010",
"randomInt": 1,
"arrayOfObjs": [{
"objid": "string_data",
"mytimestamp": "xxxxxxxxxxxx",
"externalRefId": "1010101010101010",
"myMap": {
"key1": "val1",
"key2": "val2"
}
}]
}
I have tried passing a basic String in place of the JSON and it works perfectly. Unfortunately, I do not know what is wrong since the JSON is correct and I validated it here https://jsonlint.com/.
I have this serialized/de-serialized separately with Apex HTTP callouts as well. However, I get an error even before I reach the deserialization section in the POST operation. It fails to just receive the JSON and tries to internally parse it.
Any help would be much appreciated.
Thanks,
Adarsh