title: Deserialize JSON with Gson in an object
body: <p>I have a JSON string such as below. That comes from a Website (the URL outputs below to a page) which I'm using in an android application.  </p>
  
  <pre><code>{"posts": [{"id":"0000001","longitude":"50.722","latitude":"-1.87817","position":"Someplace 1","altitude":"36","description":"Some place 1 "},{"id":"0000002","longitude":"50.722","latitude":"-1.87817","position":"Some PLace 2","altitude":"36","description":"Some place 2 description"}]}
  </code></pre>
  
  <p>I would like to deserialize this into a List where I can iterate through them later on the application. How do I do this? I have created a class with properties and methods and a List class as below and then using <code>fromJson</code> to deserialize it, but it returns NULL. Hope the question is clear and many thanks in advance.</p>
  
  <p><strong>ListClass</strong></p>
  
  <p>package dataaccess;</p>
  
  <pre><code>import java.util.List;
  
  public class LocationList {
      public static List&lt;Location&gt; listLocations;
  
      public void setLocationList(List &lt;Location&gt; listLocations) {
          LocationList.listLocations = listLocations;
      }
  
      public List&lt;Location&gt; getLocationList() {
          return listLocations;
      }
  }
  </code></pre>
  
  <p><strong>GSON</strong></p>
  
  <pre><code>public LocationList[] getJsonFromGson(String jsonURL) throws IOException{
      URL url = new URL(jsonURL);
      String content = IOUtils.toString(new InputStreamReader(url.openStream()));
      LocationList[] locations =  new Gson().fromJson(content, LocationList[].class);
  
      return locations;
  }
  </code></pre>