+ 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;
    }