title: GSON Deserializing Array of Custom Objects
body: <p>I am trying to serialize/deserialize JSON in Android using GSON. I have two classes that look like this:</p>
  
  <pre><code>public class Session {
  @SerializedName("name")
  private String _name;
  @SerializedName("users")
  private ArrayList&lt;User&gt; _users = new ArrayList&lt;User&gt;();
  }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>public class User {
  @SerializedName("name")
  private String _name;
  @SerializedName("role")
  private int _role;
  }
  </code></pre>
  
  <p>I am using GSON for serializing/deserializing the data. I serialize like so:</p>
  
  <pre><code>Gson gson = new Gson();
  String sessionJson = gson.toJson(session);
  </code></pre>
  
  <p>This will produce JSON that looks like this:</p>
  
  <pre><code>{
  "name":"hi",
      "users":
  [{"name":"John","role":2}]
  }
  </code></pre>
  
  <p>And I deserialize like so:</p>
  
  <pre><code>Gson gson = new Gson();
  Session session = gson.fromJson(jsonString, Session.class);
  </code></pre>
  
  <p>I'm getting an error when I make this call.</p>
  
  <pre><code>DEBUG/dalvikvm(739): wrong object type: Ljava/util/LinkedList; Ljava/util/ArrayList;
  WARN/System.err(739): java.lang.IllegalArgumentException: invalid value for field
  </code></pre>
  
  <p>I don't know what this error means. I don't see myself doing anything gravely wrong. Any help? Thanks! </p>