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
Sanchivan SivadasanSanchivan Sivadasan 

Exception: System.JSONException: Illegal value for primitive

Hi there,

 

I am getting the following ERROR:

Exception: System.JSONException: Illegal value for primitive

When I try to deserialize the HTTP response from Jive to an object.

 

JivePersonObject personRecord = (JivePersonObject) System.JSON.deserialize(jiveResponse, JivePersonObject.class);

 

I have validated the JSON string at http://jsonlint.com/ and it is valid. 

 

This is not happening for all the response. It is happening for some response and some of them don't have the issue.

 

I was wondering if anyone have come across this issue before. Not sure what I am doing wrong here. Thanks.

 

Sanch

James LoghryJames Loghry
The response you are getting back does not match the JivePersonObject class.  It sounds like the JivePersonObject class has a primitive variable like a boolean, string, int, dateTime, etc, where the response is returning a complex object.  I would compare the response and your JivePersonObject class to find out where the exact issue is and then fix it.

You could also use the following app and compare how the output looks to your JivePersonObject class: http://json2apex.herokuapp.com
Chris Toews 9Chris Toews 9
Thanks James, that app was great. It helped me to see that the JSON parser was parsing some of my items as 'List<String>'. I'm not sure why the parser was doing this, but I was able to get around it. I am using a custom class for this.
I found when I tried to use a custom SObject, the parser didn't like that all my JSON parameters didn't end in '__C'.

I used the following methods to make my class play nice with the Parser, and my other code.
    public void setoffice(String thisoffice){
        this.office = new List<String>{thisoffice};
    }
    
    public void setoffice(List<String> thisoffice){
        this.office = thisoffice;
    }
   
    
    public String getoffice(){
        if(this.office == null) return null;
        String result = '';
        for(String s:this.office){
            result += s;
        }
        return result;
    }


 
David Roberts 4David Roberts 4
I had the same error.
Turned out I was passing more detail than I needed to in my json object.
My class was expecting a simple list of Ids:
public List<Id> wLstAssignees {get; set;}
but I was sending a compound object:
"wLstAssignees": [{
			"wId": "0038E00001BO4U2QAL",
			"wMemberName": "First Last",
			"wSelected": true,
			"wTeamName": "Team2"
		}],

I simplified the construction to just include the Id and it worked fine.

I could have added a wrapper class with those items, but didn't need to in my case.
@AuraEnabled public List<AssigneeWrapper> wLstAssignees {get; set;}

private class AssigneeWrapper{
        @AuraEnabled public Id wId {get; set;}
        @AuraEnabled public String wMemberName {get; set;}
        @AuraEnabled public Boolean wSelected {get; set;}
        @AuraEnabled public String wTeamName {get; set;}
 }//AssigneeWrapper