title: How to serialize JSON array to a Java Object using GSON?
body: <p>I have a below JSON document which I need to parse. I am showing only two objects in <code>files</code> array. In general I will have more than 500 objects.</p>
  
  <pre><code>{  
     "files":[  
        {  
           "name":"/testing01/partition_395.shard",
           "max_chain_entries":20,
           "partition":"297, 298",
           "new_users":"123, 345, 12356"
        },
        {  
           "name":"/testing02/partition_791.shard",
           "max_chain_entries":20,
           "partition":"693, 694, 695",
           "new_users":"3345, 6678, 34568"
        }
     ]
  }
  </code></pre>
  
  <p>And here is my DataModel class for above object -</p>
  
  <pre><code>public class JsonResponseTest {
      private String name;
      private String max_chain_entries;
      private String partition;
      private String new_users;
  
      // getters here
  }
  </code></pre>
  
  <p>I need to extract all the <code>new_users</code> if <code>name</code> tag has <code>/testing01</code> and populate it in <code>HashSet</code> in Java. I am using GSON for JSON Serialization.</p>
  
  <pre><code>private static RestTemplate restTemplate = new RestTemplate();
  private static final Gson gson = new Gson();
  
  public static void main(String[] args) {
  
      String jsonResponse = restTemplate.getForObject(
              "some_url", String.class);
  
      Type collectionType = new TypeToken&lt;List&lt;JsonResponseTest&gt;&gt;() {}.getType();
      List&lt;JsonResponseTest&gt; navigation = gson.fromJson(jsonResponse, collectionType);
  
      System.out.println(navigation);
  }
  </code></pre>
  
  <p>But the above code is giving me error message as - </p>
  
  <pre><code>Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
  </code></pre>
  
  <p>Anything wrong I am doing here?</p>