title: How to parse a JSON twice for the same HttpResponse? (ANDROID)
body: <p>I use the library GSON to parse the response of a web service in JSON format. In the event that the web service returns me a positive response, I'll return it as a USER Class, otherwise it returns me as an ERROR Class.</p>
  
  <p>I would like, if when I'm trying to get my USER and that fails, you can recover my ERROR with the same HttpResponse but it does not work. Does anyone have an idea?</p>
  
  <pre><code>try {
      //Create an HTTP client
      HttpClient client = new DefaultHttpClient();
      HttpPost httpPost = new HttpPost(URL);
  
      //Add your POST data
      List&lt;NameValuePair&gt; post = new ArrayList&lt;NameValuePair&gt;(3);
      post.add(new BasicNameValuePair("login", login));
      post.add(new BasicNameValuePair("pwd", pwd));
      post.add(new BasicNameValuePair("id_tablet", InfoTab.getPhoneInfo(context)));
      httpPost.setEntity(new UrlEncodedFormEntity(post));
  
      //Perform the request and check the status code
      HttpResponse response = client.execute(httpPost);
      StatusLine statusLine = response.getStatusLine();
      if(statusLine.getStatusCode() == 200) {
          HttpEntity entity = response.getEntity();
          InputStream content = entity.getContent();
  
          try {
              //Read the server response and attempt to parse it as JSON
              Reader reader = new InputStreamReader(content);
  
              GsonBuilder gsonBuilder = new GsonBuilder();
              Gson gson = gsonBuilder.create();
  
              User user = gson.fromJson(reader, User.class);
  
              if(user.getIdLms()==null) {
                  Error error = gson.fromJson(reader, Error.class);
                  // ERROR TREATMENT
              } else {
                  // USER TREATMENT
              }
              content.close();
          } catch (Exception ex) {
              Log.e(getClass().getSimpleName(), "Failed to parse JSON due to: " + ex);
          }
      } else {
          Log.e(getClass().getSimpleName(), "Server responded with status code: " + statusLine.getStatusCode());
      }
  } catch(Exception ex) {
      Log.e(getClass().getSimpleName(), "Failed to send HTTP POST request due to: " + ex);
  }
  </code></pre>