title: Gson throwing JSON Error “java.lang.IllegalStateException"
body: <p>I have this model: <code>Map&lt;MyObjectA, Set&lt;MyObjectB&gt;&gt;</code> where <code>MyObjectA</code> is a complex object but <code>MyObjectB</code> it's not. Both are <code>Parcelable</code>.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>{
      "my.package.models.MyObjectA@5415636": [{
          "member1": "val",
          "member2": "val",
          "member2": "val",
          ...
      }]
  }
  </code></pre>
  
  <p>This operation works:</p>
  
  <pre><code>private boolean putObject(String key, Object object) {
      ...
      return mPreferences.edit().putString(key, mGson.toJson(object)).commit();
  }
  </code></pre>
  
  <p>But this doesn't:</p>
  
  <pre><code>type = new TypeToken&lt;Map&lt;MyObjectA, Set&lt;MyObjectB&gt;&gt;&gt;() {}.getType());
  private &lt;T&gt; T getObject(String key, Type t) {
      ...
      return mGson.fromJson(mPreferences.getString(key, null), type);
  }
  </code></pre>
  
  <p>throwing:</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING
    at line 1 column 3 path $.</p>
  </blockquote>
  
  <p>I've run debug mode and used a break point at <code>line 810</code> in <code>Gson.java</code>:</p>
  
  <pre><code>...
  try {
        reader.peek();
        isEmpty = false;
        TypeToken&lt;T&gt; typeToken = (TypeToken&lt;T&gt;) TypeToken.get(typeOfT);
        TypeAdapter&lt;T&gt; typeAdapter = getAdapter(typeToken);
        T object = typeAdapter.read(reader);
        return object;
      } catch (EOFException e) {...}
  }
  </code></pre>
  
  <p><code>typeToken</code> and <code>typeAdapter</code> are correct but <code>typeAdapter.read(reader);</code> will fail...<br>
  <code>typeToken = java.util.LinkedHashMap&lt;MyObjectA, java.util.HashSet&lt;MyObjectB&gt;&gt;</code><br>
  <code>typeAdapter class com.google.gson.internal.bind.MapTypeAdapterFactory$Adapter</code></p>
  
  <p>What am I missing?<br>
  Thanks.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <pre><code>public class MyObjectA {
      private List&lt;MyObjectB&gt; list;
      private String a;
      private String b;
      private String c;
      private int one;
      private int two;
  ...
  }
  
  public class MyObjectB {
      private String x;
      private String y;
      private String z;
  ...
  }
  </code></pre>