I inherited some code that saves our application state as JSON using Gson and then reads it using fromJson .
Gson gson = createGson(); gson.fromJson(objString, myClass);
One of the saved fields is Location . Unfortunately, very rarely does parsing this stored data fail because my saved location includes mClassLoader in its mExtras, and the ClassLoader with this error cannot be created in the Gson library:
RuntimeException: failed to call protected java.lang.ClassLoader () without arguments
Does anyone know why ClassLoader is included in additional parameters for my location and should it end in a JSON view?
I suppose I can fix this by simply saving the key fields from the Location object separately (for example, longitude, latitude, height, time, accuracy), but it would be nice to save the Location object if possible.
I saw that there is an ExclusionStrategy object that I could use to exclude fields, but I was not sure if I could / could use this to exclude extra functions from within my location ...
FYI, here is the JSON data for my location object (with changing longitude and latitude to hide me):
{ <snip> "lastKnownLocation": { "mResults": [ 0, 0 ], "mProvider": "gps", "mExtras": { "mParcelledData": { "mOwnObject": 1, "mObject": 5525040 }, "mClassLoader": { "packages": {} }, "mMap": {}, "mHasFds": false, "mFdsKnown": true, "mAllowFds": true }, "mDistance": 0, "mTime": 1354658984849, "mAltitude": 5.199999809265137, "mLongitude": -122.4376, "mLon2": 0, "mLon1": 0, "mLatitude": 37.7577, "mLat1": 0, "mLat2": 0, "mInitialBearing": 0, "mHasSpeed": true, "mHasBearing": false, "mHasAltitude": true, "mHasAccuracy": true, "mAccuracy": 16, "mSpeed": 0, "mBearing": 0 }, <snip> }
Here is an example that contains mExtras when the code does not crash:
"mExtras": { "mParcelledData": { "mOwnsNativeParcelObject": true, "mNativePtr": 1544474480 }, "mHasFds": false, "mFdsKnown": true, "mAllowFds": true }