There is no general solution to this.
Basically, you want to do the reverse of what Object.toString()
does ... for each object. There is no general way to do that.
If you knew what the toString()
methods of items were generating, and the strings they were generating contained all of the information content of the original item objects, then it would be possible (in theory) to write a custom method to parse the strings. But you'd need to code the parse methods yourself.
The real solution is probably to serialize your ArrayList<Item>
directly. If necessary, solve the problem that is preventing that from working.
You ask:
can I save serialized item array to sharedprefrences
Since you are using the ObjectSerializer
class from org.apache.pig
, you will be using regular Java object serialization.
That means that you can serialize an ArrayList<Item>
if only if the Item
class can be serialized.
And that, in turn, requires the following:
Item
must implement Serializable
(directly or indirectly) AND:
- all non-volatile instance fields of
Item
must be serializable, OR
Item
must override writeObject
and readObject
, OR
Item
must also implement Externalizable
.
For a field to be serializable, it must be a primitive type, a serializable object type, or an array of a serializable type. A lot of Java library types implement Serializable
; e.g. the primitive wrappers, String
, the Collection
types, and so on.