title: Using GSON to deserialize nested array
body: <p>Giving</p>
  
  <p><strong>JSON</strong></p>
  
  <pre><code>// imagine this is JSON of a city
  {
      "title" : "Troy"
      "people" : [
          {
              {
                  "title" : "Hector",
                  "status" : "Dead"
              },
              {
                  "title" : "Paris",
                  "status" : "Run Away"
              }
          },
          ...
      ],
      "location" : "Mediteranian",
      "era" : "Ancient",
      ...
  }
  </code></pre>
  
  <p><strong>City</strong></p>
  
  <pre><code>public class City {
      @SerializeName("title")
      String title;
      @SerializeName("people")
      List&lt;Person&gt; people;
      @SerializeName("location")
      String location;
      @SerializeName("era")
      String era;
      ...
  }
  </code></pre>
  
  <p><strong>Person</strong></p>
  
  <pre><code>public class Person {
      @SerializeName("title")
      private String title;
      @SerializeName("status")
      private String status;
  }
  </code></pre>
  
  <p>If having string of JSON above, it is possible to create list of person</p>
  
  <p>A. without having to deserialize City first like following</p>
  
  <pre><code>City city = new Gson().fromJson(json, City.class)
  ArrayList&lt;Person&gt; people = city.people;
  </code></pre>
  
  <p>And </p>
  
  <p>B. without having to convert string to JSONObject, get JSONArray and then convert back to string like following</p>
  
  <pre><code>String peopleJsonString = json.optJSONArray("people").toString
  ArrayList&lt;Person&gt; people = new Gson().fromJSON(peopleJsonString, Person.class);
  </code></pre>