I was able to quickly setup the web service fixture using all goodness of dependency injection for callouts in apex, as discussed in this post.
“JSON response vs JSONObject Parser” the bloody war !
I firstly got this exception about “Missing Value”
After doing some googling, I found this post, where the code snippet indicated that newlines might be an issue with the parser. So I removed both “\r” & “\n” chars from the JSON response, why would machine require a pretty printed JSON :) Then life moved on for a while, until I got this exception
“FATAL_ERROR|superpat.JSONObject.JSONException: Expected a , or }”
I was again thinking, now what who’s wrong here JSON or Parser :-? Again after some fighting with code, I ended up on google searching for the same and luckily found metadady already fixed this one. Many thanks to metadady, for fixing this issue and submitting a patch, I don’t know why this patch is still not applied on JSONObject since Jan 24, 2011.
Again, life moved a bit ahead, until the JSONObject started parsing some Unicode chars like “\u0026”, in the response. Again Metadady was nice enough to mention this issue with his patch, but it seems there is no clean way to handle unicode chars in Apex. So I decided to get rid of them, I really can live without these special creatures in String :(
So, I kicked off all unicode awesomeness in JSON response with something like
- it took around 10+ seconds and
- “154574” script lines for parsing a moderate json string.
Number of script statements: 154574 out of 200000 ******* CLOSE TO LIMIT
It was a strange feeling of loosing everything after you won, words can’t express it.
I was having some hope, that I can get rid of it. But but but, it was all lost when I read this post from legendary Jeff Douglas. It was an unlucky Googling day for me, if this Jeff’s post could have appeared earlier, I could be more happy guy by EOD.