I am trying to save a Firebase DataSnapshot object to sharedpreferences.
See this post in which I have devised a method that involves doing this.
...
What I have tried so far:
Using Gson.Json method. RESULT: Doesn't seem to work... I don't think the DataSnapshot class is a "POJO" type class... at least not one that will work with gson.
Using this method:
private static String toString( Serializable o ) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream( baos ); oos.writeObject( o ); oos.close(); return Base64.getEncoder().encodeToString(baos.toByteArray()); }
RESULT: Doesn't work... I don't think that the DataSnapshot class is 'Serializable'.
I thought of another method -- Just save DataSnapshot.toString() into Sharedpreferences... but then how do you get it back out again? You can't do:
DataSnapshot snapshot = new DataSnapshot().fromString([string from sharedprefs])
Any help is welcome.