Skip to main content
added 61 characters in body
Source Link
Arvind
  • 173
  • 1
  • 5
  • 18

I have a Post method where the other system will be sending me the JSON like this

[{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE(((FirstName = 'Vikram3' AND AssistantName = 'test3' )))",
    "commonIndex": 0,
    "resultSize": 0,
    "result": []
},
{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE (((FirstName = 'Vikram4' AND AssistantName = 'test4' )))",
    "commonIndex": 1,
    "resultSize": 0,
    "result": []
},
{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE (((FirstName = 'Vikram5' AND AssistantName = 'test5')))",
    "commonIndex": 2,
    "resultSize": 0,
    "result": []
    }
 ]

And below is my class which is converted to wrapper obj.

@RestResource(urlMapping='/Portqii/*')
global with sharing class Portqii {
    global class fromJSON {
        public String query;
        public Integer commonIndex; 
        public Integer resultSize;  
        public string result;
    }
    
  @HttpPost
    global static string  returnRequest(fromJSON jsonBody ) 
    {
        RestRequest     request    = RestContext.request;
        RestResponse    response   = RestContext.response;    
        response.addHeader('Content-Type','applicatin/json');
        fromJSON jsonBody1=jsonBody  ;
        jsonBody1 = (fromJSON) JSON.deserialize(request.requestBody.toString(),fromJSON.class);
        return string.valueof(jsonBody1)  ;
    }
}

And i get this error, while executing it in workbench JSON_PARSER_ERROR message: JSON request body must be an object at [line:1, column:2] errorCode: JSON_PARSER_ERROR

I have a Post method where the other system will be sending me the JSON like this

[{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE(((FirstName = 'Vikram3' AND AssistantName = 'test3' )))",
    "commonIndex": 0,
    "resultSize": 0,
    "result": []
},
{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE (((FirstName = 'Vikram4' AND AssistantName = 'test4' )))",
    "commonIndex": 1,
    "resultSize": 0,
    "result": []
},
{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE (((FirstName = 'Vikram5' AND AssistantName = 'test5')))",
    "commonIndex": 2,
    "resultSize": 0,
    "result": []
    }
 ]

And below is my class which is converted to wrapper obj.

@RestResource(urlMapping='/Portqii/*')
global with sharing class Portqii {
    global class fromJSON {
        public String query;
        public Integer commonIndex; 
        public Integer resultSize;  
        public string result;
    }
    
  @HttpPost
    global static string  returnRequest(fromJSON jsonBody ) 
    {
        RestRequest     request    = RestContext.request;
        RestResponse    response   = RestContext.response;    
        response.addHeader('Content-Type','applicatin/json');
        fromJSON jsonBody1=jsonBody  ;
        jsonBody1 = (fromJSON) JSON.deserialize(request.requestBody.toString(),fromJSON.class);
        return string.valueof(jsonBody1)  ;
    }
}

And i get this error, while executing it in workbench JSON_PARSER_ERROR message: JSON request body must be an object at [line:1, column:2] errorCode: JSON_PARSER_ERROR

I have a Post method where the other system will be sending me the JSON like this

[{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE(((FirstName = 'Vikram3' AND AssistantName = 'test3' )))",
    "commonIndex": 0,
    "resultSize": 0,
    "result": []
},
{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE (((FirstName = 'Vikram4' AND AssistantName = 'test4' )))",
    "commonIndex": 1,
    "resultSize": 0,
    "result": []
},
{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE (((FirstName = 'Vikram5' AND AssistantName = 'test5')))",
    "commonIndex": 2,
    "resultSize": 0,
    "result": []
    }
 ]

And below is my class which is converted to wrapper obj.

@RestResource(urlMapping='/Portqii/*')
global with sharing class Portqii {
    global class fromJSON {
        public String query;
        public Integer commonIndex; 
        public Integer resultSize;  
        public string result;
    }
    
  @HttpPost
    global static string  returnRequest(fromJSON jsonBody ) 
    {
        RestRequest     request    = RestContext.request;
        RestResponse    response   = RestContext.response;    
        response.addHeader('Content-Type','applicatin/json');
        fromJSON jsonBody1=jsonBody  ;
        jsonBody1 = (fromJSON) JSON.deserialize(request.requestBody.toString(),fromJSON.class);
        return string.valueof(jsonBody1)  ;
    }
}

And i get this error, while executing it in workbench JSON_PARSER_ERROR message: JSON request body must be an object at [line:1, column:2] errorCode: JSON_PARSER_ERROR

Source Link
Arvind
  • 173
  • 1
  • 5
  • 18

Error : JSON request body must be an object

I have a Post method where the other system will be sending me the JSON like this

[{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE(((FirstName = 'Vikram3' AND AssistantName = 'test3' )))",
    "commonIndex": 0,
    "resultSize": 0,
    "result": []
},
{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE (((FirstName = 'Vikram4' AND AssistantName = 'test4' )))",
    "commonIndex": 1,
    "resultSize": 0,
    "result": []
},
{
    "query": "SELECT AccountId,Birthdate,FirstName FROM Contact WHERE (((FirstName = 'Vikram5' AND AssistantName = 'test5')))",
    "commonIndex": 2,
    "resultSize": 0,
    "result": []
    }
 ]

And below is my class which is converted to wrapper obj.

@RestResource(urlMapping='/Portqii/*')
global with sharing class Portqii {
    global class fromJSON {
        public String query;
        public Integer commonIndex; 
        public Integer resultSize;  
        public string result;
    }
    
  @HttpPost
    global static string  returnRequest(fromJSON jsonBody ) 
    {
        RestRequest     request    = RestContext.request;
        RestResponse    response   = RestContext.response;    
        response.addHeader('Content-Type','applicatin/json');
        fromJSON jsonBody1=jsonBody  ;
        jsonBody1 = (fromJSON) JSON.deserialize(request.requestBody.toString(),fromJSON.class);
        return string.valueof(jsonBody1)  ;
    }
}

And i get this error, while executing it in workbench JSON_PARSER_ERROR message: JSON request body must be an object at [line:1, column:2] errorCode: JSON_PARSER_ERROR