java.io.NotSerializableException: com.google.gson.internal.LinkedTreeMap$1
See original GitHub issueWhat 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.j
ava: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:3
81)
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)
Original issue reported on code.google.com by jaroslav...@lemberg.co.uk
on 23 Jan 2015 at 1:45
Issue Analytics
- State:
- Created 9 years ago
- Comments:6
Top Results From Across the Web
GSON not serializable in JSF managed bean - Stack Overflow
In your code I can't see it, but it looks like there's a member variable containing a Gson , possibly indirectly (It can...
Read more >NotSerializableException in Java with Examples
In Java, a NotSerializableException exception is thrown when an instance of a class must implement the Serializable interface. The exception is ...
Read more >NotSerializableException (Java SE 11 & JDK 11 )
Thrown when an instance is required to have a Serializable interface. The serialization runtime or the class of the instance can throw this...
Read more >Spark Error Task Not Serializable | The Startup - Medium
Cause of Task Not Serializable exception in Spark. Discusses functional interfaces in Java/Scala, closures, ObjectOutputStream. ... Caused by: java.io.
Read more >groovy.json.internal.LazyMap error - Jenkins Jira
When I use below method after parsing the JSON using JsonSlurper(), I am getting java.io.NotSerializableException: groovy.json.internal.LazyMap error.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Adding:
-keep class com.google.gson.** { *; }
to the
proguard-rules.pro
fix this issue.Any newcomers to this issue, you only need to add the following to your proguard rules:
-keep class com.google.gson.internal.LinkedTreeMap { *; }