Apex REST Web Service: Unexpected parameter encountered during deserialization

Any thoughts on why the REST web service below does not properly deserialize the input argument?

Unit test passes. CURL request (below) returns error.

global with sharing class TestService {

    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"}' 


[{"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"}}'


"req": {
    "testArg": "testValue"

The request data should be as shown above .

I had blogged on this topic may be that can be helpful to you


The deserialization happens with parameter name in sfdc.

Also just out of topic but its better to keep Test class in separate class as per new sfdc guidelines for test class

SFDC Documentation Link:


Source : Link , Question Author : dlog , Answer Author : Mohith Shrivastava

Leave a Comment