Any thoughts on why the REST web service below does not properly deserialize the input argument?
Unit test passes. CURL request (below) returns error.
@RestResource(urlMapping='/test/*') global with sharing class TestService { @HttpPost global static string doPost(TestRequest req){ return req.testArg; } private static testMethod void tests(){ TestRequest req = new TestRequest(); req.testArg = 'hello'; String result = TestService.doPost(req); System.assertEquals('hello', result); } global class TestRequest{ global string testArg; } }
Test Request
curl -X POST -H 'Authorization: Bearer sessionID' -H 'Content-Type: application/json' -d '{"testArg": "testValue"}' 'https://power-site-5184.database.com/services/apexrest/test'
Response
[{"message":"Unexpected parameter encountered during deserialization: testArg at [line:1, column:14]","errorCode":"JSON_PARSER_ERROR"}]
Update (resolved)
The correct JSON data structure should be
-d '{"req": {"testArg": "testValue"}}'