title: How to parse response with Gson
body: <p>I have an Android application, this application can contact a webservices, that response throught JSON, and send an object. I want to use a Gson library to convert the response in Object. So I have this method but not works.</p>
  
  <pre><code>      private static Impresa getDatiImpresa(String url) throws 
          IOException, MalformedURLException, JSONException
          {
              String result = "";
              Gson gson = new Gson();
              HttpClient client = new DefaultHttpClient();
              HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
              HttpResponse response;
              try {
                  HttpPost post = new HttpPost(url);
                  response = client.execute(post);
  
                  /*Checking response */
                  if(response!=null){
  
                      InputStream source = response.getEntity().getContent(); //Get the data in the entity
                      Reader reader = new InputStreamReader(source);
                      Impresa impresa = gson.fromJson(reader, Impresa.class);
                     return impresa;
                  }
  
              } catch(Exception e) {
                  e.printStackTrace();
                  //createDialog("Error", "Cannot Estabilish Connection");
              }
              return null;
          }
  
  public class Impresa {
      @SerializedName("pivaImpresa")
      public String partitaIVA;
      @SerializedName("ragioneSociale")
      public String ragioneSociale;
      @SerializedName("centriAziendali")
      public List&lt;CentroAziendale&gt; listaCentroAziendale;
  
      public String getPartitaIVA() {
          return partitaIVA;
      }
      public void setPartitaIVA(String partitaIVA) {
          this.partitaIVA = partitaIVA;
      }
      public String getRagioneSociale() {
          return ragioneSociale;
      }
      public void setRagioneSociale(String ragioneSociale) {
          this.ragioneSociale = ragioneSociale;
      }
      public List&lt;CentroAziendale&gt; getListaCentroAziendale() {
          return listaCentroAziendale;
      }
      public void setListaCentroAziendale(List&lt;CentroAziendale&gt; listaCentroAziendale) {
          this.listaCentroAziendale = listaCentroAziendale;
      }
  }
  </code></pre>
  
  <p>This method return null everytime.</p>
  
  <p>I have use this code to read the response of web services.
  This is the code:</p>
  
  <pre><code>StringBuilder sb = new StringBuilder();
  BufferedReader r = new BufferedReader(new InputStreamReader(new DoneHandlerInputStream(source)));
  for (String line = r.readLine(); line != null; line = r.readLine()){
     sb.append(line);
  }
  </code></pre>
  
  <p>this is the response of web services:</p>
  
  <pre><code>{"status":1,"message":"Ok","content":[{"pivaImpresa":"05050505055","ragioneSociale":"Azienda Giustina","centriAziendali":[{"pivaImpresa":"05050505055","codiceCentroAziendale":"C001"}]}]}
  </code></pre>