-3

This question was asked many times, but I haven't found a good solution yet. I want to store my Arraylist in the sharedpreferences in Android as a String. So how can I serialize and deserialize it?

Any solutions?

progNewbie
  • 4,362
  • 9
  • 48
  • 107

2 Answers2

2

Try using Gson Library this way:

String json = new Gson().toJson(<your list>);

To add Gson library add to dependencies

compile "com.google.code.gson:gson:2.6.2"
Marco Pierucci
  • 1,125
  • 8
  • 23
0

You can supply a toString() method for your custom objects then call toString() on the ArrayList. Parsing the string to deserialize it will be more difficult.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268