-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gson 2.8,.6 fails to serialize/deserialize SparseArray on Android 10 #1660
Comments
You should not (de)serialize objects of classes you don't control and don't know it's structure. What you should do: convert your sparse array to a DTO object that is Gson-friendly (simple built-ins like List, Map). Why: Gson does not support the Android runtime classes directly, and mostly picks up a type adapter that (de)serializes the object field-by-field including its private fields that are not excluded (neither transient, nor excluded explicitly). You probably need to implement a custom type adapter too for the reasons of backwards compatibility. See more: #1573 #1613 |
The exact same problem happens with Json-IO: It works fine on Android 9 and below, but on Android 10/11, Json-IO will save a The solution/workaround is to use Note that |
Closing this issue because as mentioned in #1660 (comment) you should not rely on reflection-based serialization for third-party classes. |
I'm using Gson in my @TypeConverter class to convert SparseArray objects into json String to be saved in Room database. Here is how I do it:
`class RoomTypeConverter {
}`
The TypeConverter works fine for Android 9 and below as SparseArray successfully converted as JSON string, but fails to work properly on Android 10 as the JSON string saved in database are just empty JSON "{}".
The text was updated successfully, but these errors were encountered: