I want to serial a custom Java object, so I My items: Serialization: serializeWithJSON (): Deserialization: Exception: I do not understand why GSON wants to insert EDIT: It seems that SparseArray is correctly deserialized, but not inside the objects. Instead of SharedPreferences I can use it in another activity. I do not need constant storage,
shared references , when my application stops, I erase them. I am currently using GSON for this, but it does not seem to work well with Android's Spurs Array type.
Public class partprofile {Private int game ID; // Some more primitive personal sparsarer & lt; Part & gt; InstallParts = new SparseArray & lt; Part & gt; (); // ...} public square part {private string partName; // more primitives}
Type
genericType = new TypeToken & lt; PartProfile & gt; () {} .getType (); String Serialized Profiles = Helpers Cyrillous Withs (Installed Perts, Generic Type); Preferences.edit () PutString ("Parts", Cyrilized Profiles) .commit ();
public static string serializedJason (object o, type generic type) {gsan gsn = new gsan (); Return gson.toJson (o, generic type); }
Type
genericType = new TypeToken & lt; PartProfile & gt; () {} .getType (); Partprofile Parts = GSN.frame Jason (preferences.getString ("Parts", "PARTS_ERROR"), generic type); SparseArray & LT; Part & gt; RetreivedParts = parts.getInstalledParts (); Int key; For (int i = 0; i & lt; retreivedParts.size (); i ++) {key = retreivedParts.keyAt (i); // Exception here: Part part = retreivedParts.get (key); // ...}
java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap should not be entered in com Could. Mypackage.objects.Part
LinkedTreeMap on my object, I can always use one of my entire programs I do not use Send me the
SparseArray & lt; Part & gt; Before switching to , and there was never a problem with it, I have
hashmap and lieutenant; Integer, part & gt; Is SparseArrays not supported by GSO, or is there any error in my favor?
LinkedTreeMaps , this type should be
part .
No comments:
Post a Comment