Issue 621 in google-gson: java.io.NotSerializableException: com.google.gson.internal.LinkedTreeMap$1

296 views
Skip to first unread message

googl...@googlecode.com

unread,
Jan 23, 2015, 8:46:02 AM1/23/15
to google-gson...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 621 by jaroslav...@lemberg.co.uk:
java.io.NotSerializableException: com.google.gson.internal.LinkedTreeMap$1
https://code.google.com/p/google-gson/issues/detail?id=621

What version of the product are you using? Gson 2.3.1
On what operating system? ArchLinux x86

What steps will reproduce the problem?
1. Create a Parcelable object which contains a Map which is filled by Gson
private Map<String, ?> mMap;

2.Write this map as a Serilizable in writeToParcel (I do this because I
need to maintain Gson property order. If I do dest.writeMap() I will obtain
a HashMap when creating from Parcel)
dest.writeSerializable((Serializable) mMap);

3. Obfuscate this with Proguard (not obfuscaed code not crashing).
4. Invoke writeToParcel()

What is the expected output?
No crash

What do you see instead?

java.lang.RuntimeException: Parcelable encountered IOException writing
serializable object (name = com.google.gson.internal.LinkedTreeMap)
at android.os.Parcel.writeSerializable(Parcel.java:1388)
at
com.smartatoms.lametric.model.device.DeviceInfoApp.writeToParcel(DeviceInfoApp.java:115)
at android.os.Parcel.writeParcelable(Parcel.java:1357)
at android.os.Parcel.writeValue(Parcel.java:1262)
at android.os.Parcel.writeList(Parcel.java:711)
at android.os.Parcel.writeValue(Parcel.java:1284)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at
android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at
android.support.v4.app.FragmentState.writeToParcel(Fragment.java:137)
at android.os.Parcel.writeTypedArray(Parcel.java:1191)
at
android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:381)
at android.os.Parcel.writeParcelable(Parcel.java:1357)
at android.os.Parcel.writeValue(Parcel.java:1262)
at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
at
android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
at android.os.Bundle.writeToParcel(Bundle.java:1096)
at android.os.Parcel.writeBundle(Parcel.java:663)
at
android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2884)
at
android.app.ActivityThread$StopInfo.run(ActivityThread.java:3261)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: java.io.NotSerializableException:
com.google.gson.internal.LinkedTreeMap$1
at
java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1344)
at
java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at
java.io.ObjectOutputStream.writeFieldValues(ObjectOutputStream.java:959)
at
java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:360)
at
java.io.ObjectOutputStream.writeHierarchy(ObjectOutputStream.java:1054)
at
java.io.ObjectOutputStream.writeNewObject(ObjectOutputStream.java:1384)
at
java.io.ObjectOutputStream.writeObjectInternal(ObjectOutputStream.java:1651)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1497)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1461)
at android.os.Parcel.writeSerializable(Parcel.java:1383)
            at
com.smartatoms.lametric.model.device.DeviceInfoApp.writeToParcel(DeviceInfoApp.java:115)
            at android.os.Parcel.writeParcelable(Parcel.java:1357)
            at android.os.Parcel.writeValue(Parcel.java:1262)
            at android.os.Parcel.writeList(Parcel.java:711)
            at android.os.Parcel.writeValue(Parcel.java:1284)
            at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
            at
android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
            at android.os.Bundle.writeToParcel(Bundle.java:1096)
            at android.os.Parcel.writeBundle(Parcel.java:663)
            at
android.support.v4.app.FragmentState.writeToParcel(Fragment.java:137)
            at android.os.Parcel.writeTypedArray(Parcel.java:1191)
            at
android.support.v4.app.FragmentManagerState.writeToParcel(FragmentManager.java:381)
            at android.os.Parcel.writeParcelable(Parcel.java:1357)
            at android.os.Parcel.writeValue(Parcel.java:1262)
            at android.os.Parcel.writeArrayMapInternal(Parcel.java:638)
            at
android.os.BaseBundle.writeToParcelInner(BaseBundle.java:1313)
            at android.os.Bundle.writeToParcel(Bundle.java:1096)
            at android.os.Parcel.writeBundle(Parcel.java:663)
            at
android.app.ActivityManagerProxy.activityStopped(ActivityManagerNative.java:2884)
            at
android.app.ActivityThread$StopInfo.run(ActivityThread.java:3261)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)



--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

googl...@googlecode.com

unread,
Feb 2, 2015, 11:27:56 AM2/2/15
to google-gson...@googlegroups.com

Comment #1 on issue 621 by d3M1d...@gmail.com:
java.io.NotSerializableException: com.google.gson.internal.LinkedTreeMap$1
https://code.google.com/p/google-gson/issues/detail?id=621

Hi. Today got this crash. Gson parsed my object like
ArrayList<LinkedTreeMap<Node<String, String>. This object convert to byte[]
like this :

ByteArrayOutputStream outStream = new ByteArrayOutputStream();
objOutStream = new ObjectOutputStream(outStream);
objOutStream.writeObject(obj);

So, I got exception :

java.io.NotSerializableException:
ru.tcsbank.wallet.gson.patched.internal.LinkedTreeMap$1
and could not write serialized object to byte array.

googl...@googlecode.com

unread,
Feb 2, 2015, 11:30:39 AM2/2/15
to google-gson...@googlegroups.com

Comment #2 on issue 621 by d3M1d...@gmail.com:
java.io.NotSerializableException: com.google.gson.internal.LinkedTreeMap$1
https://code.google.com/p/google-gson/issues/detail?id=621

And yes. I dont know about true reason, but if I dont have proguard, this
code works perfect.

googl...@googlecode.com

unread,
May 5, 2015, 10:21:48 PM5/5/15
to google-gson...@googlegroups.com

Comment #3 on issue 621 by spark...@gmail.com:
java.io.NotSerializableException: com.google.gson.internal.LinkedTreeMap$1
https://code.google.com/p/google-gson/issues/detail?id=621

I ran into this same issue and it appears to be a configuration issue with
the default proguard file provided by google (in my case of android). You
basically need to maintain additional methods when it comes to serializable
classes. You can read section "Processing serializable classes" here for
more info http://proguard.sourceforge.net/manual/examples.html#serializable

Long story short, add this to your proguard file so they aren't stripped
out.
-keepclassmembers class * implements java.io.Serializable {
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();

googl...@googlecode.com

unread,
May 6, 2015, 6:43:40 AM5/6/15
to google-gson...@googlegroups.com

Comment #4 on issue 621 by jaroslav...@lemberg.co.uk:
java.io.NotSerializableException: com.google.gson.internal.LinkedTreeMap$1
https://code.google.com/p/google-gson/issues/detail?id=621

Haven't tested this but spark's comment seems reasonable. I guess this
issue should be closed as user error.

googl...@googlecode.com

unread,
Jun 1, 2015, 11:41:13 PM6/1/15
to google-gson...@googlegroups.com

Comment #5 on issue 621 by cha...@gmail.com:
java.io.NotSerializableException: com.google.gson.internal.LinkedTreeMap$1
https://code.google.com/p/google-gson/issues/detail?id=621

This should be added to some of the serializable notes somewhere in the
android guide. By default when building using AndroidStudio, the bug did
not show up in the debug build but it shows in the release build.
Reply all
Reply to author
Forward
0 new messages