title: TinyDB - SharedPreferences - getting: Forgot to register a type adapter?
body: <p>I just discovered <a href="https://github.com/kcochibili/TinyDB--Android-Shared-Preferences-Turbo" rel="nofollow">TinyDB</a> which seems quite useful to handle object storage into the SharedPreferences.</p>
  
  <p>I'm almost there but I'm getting an error: <strong>Forgot to register a type adapter?</strong> 
  Note that the GSON library from Google is used together with TinyDB.</p>
  
  <p>So, let me share my code with you. Any help would be highly appreciated.</p>
  
  <p><strong>Here is the stackTrace</strong></p>
  
  <pre><code>java.lang.UnsupportedOperationException: Attempted to serialize
  java.lang.Class: com.ilepez.weatherapp.data.model.CityArrayList. Forgot to register a type adapter?
  at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:76)
  at com.google.gson.internal.bind.TypeAdapters$1.write(TypeAdapters.java:69)
  at com.google.gson.Gson.toJson(Gson.java:669)
  at com.google.gson.Gson.toJson(Gson.java:648)
  at com.google.gson.Gson.toJson(Gson.java:603)
  at com.google.gson.Gson.toJson(Gson.java:583)
  at com.ilepez.weatherapp.utils.TinyDB.putObject(TinyDB.java:462)
  at com.ilepez.weatherapp.activity.SearchActivity.onItemClick(SearchActivity.java:67)
  at android.widget.AutoCompleteTextView.performCompletion(AutoCompleteTextView.java:928)
  at android.widget.AutoCompleteTextView.access$500(AutoCompleteTextView.java:93)
  at android.widget.AutoCompleteTextView$DropDownItemClickListener.onItemClick(AutoCompleteTextView.java:1230)
  at android.widget.AdapterView.performItemClick(AdapterView.java:345)
  at android.widget.AbsListView.performItemClick(AbsListView.java:1547)
  at android.widget.AbsListView$PerformClick.run(AbsListView.java:3821)
  at android.widget.AbsListView$3.run(AbsListView.java:5841)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:158)
  at android.app.ActivityThread.main(ActivityThread.java:7229)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
      07-17 10:55:26.283 15392-15392/com.ilepez.weatherapp E/libEGL: call to OpenGL ES API with no current context (logged once per thread)
  </code></pre>
  
  <p>So, let me share my code with you. Any help would be highly appreciated.</p>
  
  <p><strong>So here is the moment when I add my object to TinyDB</strong></p>
  
  <pre><code>City city = new City(description, itemLatitude, itemLongitude);
                  ArrayList&lt;Object&gt; savedCity = new ArrayList&lt;&gt;();
                  savedCity.add(city);
  for (City oCity : CityArrayList.getInstance().getCityList()) {
      savedCity.add(oCity);
  }
  
  TinyDB tinydb = new TinyDB(this);
  tinydb.putObject("city", CityArrayList.class);
  </code></pre>
  
  <p><strong>Here is my model</strong></p>
  
  <pre><code>public class CityArrayList {
  
      public ArrayList&lt;City&gt; cityList;
  
      private CityArrayList() {
          cityList = new ArrayList&lt;City&gt;();
      }
  
      public ArrayList&lt;City&gt; getCityList() {
          return cityList;
      }
  
      private static CityArrayList instance;
  
      public static CityArrayList getInstance() {
          if (instance == null) instance = new CityArrayList();
          return instance;
      }
  }
  </code></pre>
  
  <p><strong>And for the city itself</strong></p>
  
  <pre><code>public class City {
  
      private String cityName;
      private double cityLat;
      private double cityLong;
  
      public City(String cityName, double cityLat, double cityLong) {
          this.cityName = cityName;
          this.cityLat = cityLat;
          this.cityLong = cityLong;
      }
  
      public String getCityName() {
          return cityName;
      }
  
      public void setCityName(String cityName) {
          this.cityName = cityName;
      }
  
      public double getCityLat() {
          return cityLat;
      }
  
      public void setCityLat(double cityLat) {
          this.cityLat = cityLat;
      }
  
      public double getCityLong() {
          return cityLong;
      }
  
      public void setCityLong(double cityLong) {
          this.cityLong = cityLong;
      }
  
      @Override
      public String toString() {
          return "City{" +
                  "cityName='" + cityName + '\'' +
                  ", cityLat=" + cityLat +
                  ", cityLong=" + cityLong +
                  '}';
      }
  }
  </code></pre>