title: ANDROID : deserialise json string from file to class object
body: <p>I am trying to figure out how to save my Todo List in a file and then obtain it when I reopen the application. So far, my entries are saving to file correctly as a string, but I don't know how to get them back out of the string and display on screen. I guess I have to deserialize it, but I don't know how that works and would really appreciate some help.</p>
  
  <p>This is a sample of my code:</p>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  ArrayList&lt;Entry&gt; mEntries;
  String json;
  Gson gson;
  File dir, saveLocation;
  FileWriter file1;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      gson = new Gson();
      try {
          BufferedReader br = new BufferedReader(new FileReader(new File(dir,"storage.json")));
          Entry e = gson.fromJson(br, Entry.class); 
        //I'm stuck here, Don't know how to proceed
  
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      }
  
   @Override
   protected void onStop() {
      super.onStop();
      json = gson.toJson(mEntries);
      Log.d("jsondata", json);
      try {
          dir = getFilesDir();
          saveLocation = new File(dir,"storage.json");
          file1 = new FileWriter(saveLocation);
          file1.write(json);
          file1.flush();
          file1.close();
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Entry.java</strong></p>
  
  <pre><code>public class Entry {
  String S;
  boolean b;
  
  public Entry(String S, boolean b) {
      this.S = S;
      this.b = b;
  }
  //Getter and Setter methods
  </code></pre>
  
  <p>A sample of the json saved in the file:</p>
  
  <p>[{"S":"hello there","b":false},{"S":"task1","b":true},{"S":"task2","b":false}]</p>
  
  <p>// Here S is the task to do and b is whether it is done or not</p>