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
Kunal Purohit 4Kunal Purohit 4 

How to map json in case of reserved keyword?

Hello Team,
i am writing Webservice and want to map json.But in debug log shows status ""For input string: "" at [line:1, column:218]..

Here is Json Response:
invoice":{"id":2651,"number":"In-151","poNumber":""}

Here is the code:
@RestResource(urlMapping='/Invoice/*')
global class GetInvoiceFromTeamWork {
	@HttpPost
    global static void doPost() {
        RestRequest req = RestContext.request;
        String jsonresponse = req.requestBody.toString();
        system.debug('jsonresponse'+jsonresponse);
        
        
        wrapperofInvoice wrapinvoice=(wrapperofInvoice)JSON.deserialize(jsonresponse, wrapperofInvoice.class);
        TW_Invoice__c inv =new TW_Invoice__c();
        inv.TW_Invoice_ID__c=wrapinvoice.invoice.id;
        
        //inv.TW_PO_Number__c=wrapinvoice.invoice.poNumber;
        insert inv;   
    }
    
    public class wrapperofInvoice{
        public eventCreator eventCreator;
        public Invoice invoice;
    }
    
    public class eventCreator {
        public String wholeJson;
    }
    
    public class invoice{
        Public integer id;
        public integer number;
        public decimal poNumber;
        public String description;
       public String Status;
        public String currencyCode;
	public String dateCreated;        
    }
}

 
AnudeepAnudeep (Salesforce Developers) 
This happens if you are trying to put a Decimal value into an Integer. I recommend checking your JSON. 

In your JSON, if it appears as a Decimal value you might want to change your code

I recommend reviewing this post as a reference

Let me know if this helps, if it does, please close the query by marking it as solved. It may help others in the community. Thank You!