System for saving objects

Naw my code look like this:

void Save()
{  
  Gson gson = new Gson();
  String json = "0";
  JSONObject js;
  JSONArray values = new JSONArray();

  switch(mode) {
  case 1:
    for (int i = 0; i<cir.size(); i++)
    {
      json = gson.toJson(cir.get(i));
      js = parseJSONObject(json);
      values.setJSONObject(i, js);
    }
    break;
  case 2:
    if (pendul)
    {
      for (int i = 0; i< pend.size(); i++)
      {
        json = gson.toJson(pend.get(i));
        js = parseJSONObject(json);
        values.setJSONObject(i, js);
      }
    } else 
    {
      for (int i = 0; i< doublePend.size(); i++)
      {
        json = gson.toJson(doublePend.get(i));
        js = parseJSONObject(json);
        values.setJSONObject(i, js);
      }
    }
    break;
  }
  
  save.saves(values);
}

class SaveGame
{
  Gson gson; 
  String json;
  JSONObject js;

  SaveGame()
  {
    gson = new Gson();
  }

  void saves(JSONArray obj)
  {
 
    boolean exist = true;
    if (obj != null)
    {
      File f;
      int i = -1;
      do
      {
        i++;
        f = dataFile("saves/save" + i + ".txt");     
        exist = f.isFile();
      }
      while (exist);
      println(f, " ",obj);
      saveJSONArray(obj, "saves/save" + i + ".txt");
    }  
  }
}```