title: How to convert JSON objects to POJO from Gson
body: <p>I am trying to convert JSON objects to POJO's with GSON. </p>
  
  <p>JSON String</p>
  
  <pre><code>[
    {
      "automation_project": {
        "user_id": null,
        "name": "Untitled Project",
        "updated_at": "2015-06-16T19:39:42Z",
        "group_id": 764496,
        "created_at": "2014-11-23T01:01:59Z",
        "id": 16214
      }
    },
    {
      "automation_project": {
        "user_id": null,
        "name": "newintropage",
        "updated_at": "2015-06-16T21:20:47Z",
        "group_id": 764496,
        "created_at": "2015-06-16T20:39:04Z",
        "id": 29501
      }
    }
  ]
  </code></pre>
  
  <p>The AutomationProjectsList class used with GSON</p>
  
  <pre><code>public class AutomationProjectsList {
  
  private List&lt;AutomationProject&gt; automationProject = new ArrayList&lt;AutomationProject&gt;();
  
  public List&lt;AutomationProject&gt; getAutomationProject() {
      return automationProject;
  }
  
  public void setAutomationProject(List&lt;AutomationProject&gt; automationProject) {
      this.automationProject = automationProject;
  }
  
  @Override
  public String toString() {
      return "AutomationProjectsList [automationProject=" + automationProject
              + "]";
  }}
  </code></pre>
  
  <p>Automation Project POJO</p>
  
  <pre><code> public class AutomationProject {
  
      private Object userId;   
      private Integer groupId;    
      private Integer id;    
      private String name;   
      private String updatedAt;   
      private String createdAt;
  
      public Object getUserId() {
          return userId;
      }
  
      public void setUserId(Object userId) {
          this.userId = userId;
      }
  
      public Integer getGroupId() {
          return groupId;
      }
  
      public void setGroupId(Integer groupId) {
          this.groupId = groupId;
      }
  
      public Integer getId() {
          return id;
      }
  
      public void setId(Integer id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getUpdatedAt() {
          return updatedAt;
      }
  
      public void setUpdatedAt(String updatedAt) {
          this.updatedAt = updatedAt;
      }
  
      public String getCreatedAt() {
          return createdAt;
      }
  
      public void setCreatedAt(String createdAt) {
          this.createdAt = createdAt;
      }}
  </code></pre>
  
  <p>The code I'm using </p>
  
  <p>JSONArray jsonArray = new JSONArray(response.getEntity(String.class));</p>
  
  <pre><code>    for(int i = 0; i &lt; jsonArray.length(); i++){
          if(jsonArray.get(i) instanceof JSONObject){
              JSONObject jsnObj = (JSONObject)jsonArray.get(i);               
              AutomationProjectsList obj = new Gson().fromJson(jsnObj.toString(), AutomationProjectsList.class);                  
              System.out.println(obj.getAutomationProject().get(0).getId());
          }
      }
  </code></pre>
  
  <p>But it gives an exception :</p>
  
  <pre><code>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  at java.util.ArrayList.rangeCheck(ArrayList.java:653)
  at java.util.ArrayList.get(ArrayList.java:429)
  at br.usp.icmc.teste.ConnectionRestClient.getBrowserStackProjects(ConnectionRestClient.java:74)
  at br.usp.icmc.teste.TestePrincipal.main(TestePrincipal.java:9)
  </code></pre>
  
  <p>Why am I receiving an IndexOutOfBoundsException exception? Where am I wrong?</p>