function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RavitejaRaviteja 

Rest Resource

Hi,

 I have created Rest resource class to accept json(POST Method) from php.

@RestResource(urlmapping='/JsonService/*')  
global class AttorneyAdapter{    
    @HttpPost
    global static void  doPost()    {        
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        string strJSON = req.requestBody.toString();          
        JSONparser parser = JSON.createParser(strJSON);           
        Type reqObj = Type.forName('MyClass');         
        MyClass myClassObj =(MyClass)parser.readValueAs(reqObj);  
             lead l=new lead();
             l.lastname=myClassObj.last_name;
             l.firstname=myClassObj.first_name;
             l.title=myClassObj.userid;
             l.state=myClassObj.state;
             l.company=myClassObj.firm_name;
             insert l;  }  }

getting  error:
message: "System.JSONException: No content to map to Object due to end of input (System Code) Class.AttorneyAdapter.doPost: line 15, column 1

Help me....

 

thanks,

Raviteja

vbsvbs

Srirama10 - There is no need to make use of the parser here. Just build the doPost method with parameters that match the json attributes. For e.g.

 

global static void  doPost(String last_name, String first_name, String userid, String state, String firm_name){        

    lead l=new lead();
    l.lastname = last_name;
    l.firstname = first_name;
    l.title = userid;
    l.state = state;
    l.company = firm_name;
    insert l;  
} 

 The mapping should be handled by SFDC and no explicit serialization is required. HTH

Nikhil DevNikhil Dev

try changing "Content-Type" to application/json

 

User-added image