You need to sign in to do that
Don't have an account?

JSON Parsing to list of custom object type error
Hey all.
I am working with the new JSON Parsing functionality, and am hitting a bit of snag trying to parse some JSON into a list of custom objects. The exact error is
Internal System Error: 1094975380-22831 (-1000130141)
Which looks like there is probably an issue with the JSON parser. I have been able to parse single instaces of an object, but have not been able to do with with a list of them yet.
Here is what the code looks like.
public class surveyAnswer { Id contact; Integer surveyId; String questionText; String questionId; String questionAnswer; public surveyAnswer(Id c, Integer s, String qt, String qi, String qa) { contact = c; surveyId = s; questionText = qt; questionId = qi; questionAnswer = qa; } } string jsonString = '[{"questionText":"BLah 1","questionId":"51345X1607X53053","surveyId":51345,"questionAnswer":2.0,"contact":"0034000000UefNI"},{"questionText":"Blah 2","questionId":"51345X1607X53100","surveyId":51345,"questionAnswer":3.0,"contact":"0034000000UefNI"},{"questionText":"blah 3","questionId":"51345X1607X53101","surveyId":51345,"questionAnswer":1.0,"contact":"0034000000UefNI"},{"questionText":"blah 4","questionId":"51345X1607X53103","surveyId":51345,"questionAnswer":1.0,"contact":"0034000000UefNI"}]'; list<surveyAnswer> answers = (List<surveyAnswer>)JSON.deserialize(JSONString, List<surveyAnswer>.class);
I thought it might be a problem with the JSON structure, but it validates just fine in JSLint, so it should be fine. This approach should be doable according to the docs at
http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_json.htm#apex_methods_system_json
Any help would be much appreciated. Thank you!
Just to validate it's not the JSON structure, I tried creating JSON using Salesforce parser (which works, it creates valid JSON) and then attempted to deserailize it got the same error. This is the code I used to attemt my 'round trip' of serializing and deserializing. The 2nd to last line is the one that fails.
Hmm, interesting. I've tried both these examples, and they run fine for me. My debug output for the second example is:
16:17:06.078 (78276000)|USER_DEBUG|[13]|DEBUG|[{"surveyId":12345,"questionText":"blah1","questionId":"id1","questionAnswer":"yup","contact":"003U0000004rmiwIAA"},{"surveyId":12345,"questionText":"blah1","questionId":"id2","questionAnswer":"nope","contact":"003U0000004rmiwIAA"}]
16:17:06.084 (84952000)|USER_DEBUG|[17]|DEBUG|(surveyAnswer:[contact=003U0000004rmiwIAA, questionAnswer=yup, questionId=id1, questionText=blah1, surveyId=12345], surveyAnswer:[contact=003U0000004rmiwIAA, questionAnswer=nope, questionId=id2, questionText=blah1, surveyId=12345])
Ah, I got it to reproduce. I had been creating the class in the normal way, and then just executing the script below the class in the console. That works fine. It's only when the class definition is part of the script itself that it errors out this way. I'll look into it.
Cool, glad I'm not crazy.
If it is just when the class is part of the execute anon that it bugs out, that's not a huge deal. It's just how I was doing my testing so it seemed like it was broken. Would be nice if we could make that work, but if I just know that I can't test it like that, then that's no big deal. I can work around that. Thanks for looking into this for me!
And thank you for the bug report. The fix for this should arrive on the production servers in a week or so.
Hi, Rich:
I am running into a similar issue: http://boards.developerforce.com/t5/Apex-Code-Development/Unable-to-use-JSON-deseralize-to-deseralize-an-object-which/td-p/352247
Was there any change being introduced for JSON.deserialize? Thanks a lot.
I'm having the same issue, the problem is with arrays and it doesn't trigger the error until you use the field.
Example:
Presuming you actually meant the MyStatus class to look like:
...then your example is working for me now.
Well... it seems they solved it. :D