Tuesday, May 15, 2012

gson error in android application while JSON parsing | type mismatch JSON error with gson

While developing an android app having loads of usage of JSON (actually REST server based), We decided to go ahead with GSON library(I think pretty awesome except following issue).

issue : It worked fine on all android phones (fyi.. tested on few Motorola,Samsung and HTC devices..) except the HTC Explorer(a good Value for money phone as a testing device even for personal usage).

btw, error was in JSON parsing (library).. and While I was trying to run,..YUCK! I was getting a "Force Close" with some type mismatch JSON based error!

Solution:
The "fix" of renaming the gson package with jarjar did the trick..
If anyone else has this problem, here's a quick solution; (fyi, we are using gson 1.6)
Steps - how-to fix it:

1) Download jarjar (http://code.google.com/p/jarjar/downloads/list)
2) Put jarjar-1.0.jar and gson-1.6.jar in the same folder
3) Create a new text file in this folder (rules.txt)
4) Write the following line in the textfile: rule com.google.gson.** com.google.myjson.@1
5) From the command line, open jarjar with the command "java -jar jarjar.jar process rules.txt gson-1.6.jar myjson-1.6.jar"
6) Replace the gson library in your project with myjson and update the imports

so what was the reason.. OOuch! many of the android devices (probably the HTC, as I observed) use GSON library for internal apps... this is what I know.. not sure :) ..

Droid guys! Stay tuned for more bugs..ah! solutions ;)

No comments:

Post a Comment