title: How to deserialize JSON object from generic type in Java?
body: <p>I am trying to map JSON response as below:</p>
  
  <pre><code>{
      object: {
      id: 1
      name: "my name"
      email: "username@mail.com"
      username: "username"
      password: "password"
      mobile: "##########"
      fbAccessToken: "----------"
      img: null
      }
      errorMessage: ""
      successMessage: ""
      technicalErrorMessage: ""
      error: false
    }
  </code></pre>
  
  <p>so I wrote this method:</p>
  
  <pre><code>private &lt;T&gt; ResponseEntity&lt;T&gt; processedRequest(HttpRequestBase requestBase, Class&lt;T&gt; tClass) throws IOException {
          HttpResponse response = httpClient.execute(requestBase);
          HttpEntity entity = response.getEntity();
          Reader reader = new InputStreamReader(entity.getContent());
  
          Type type = new TypeToken&lt;ResponseEntity&lt;T&gt;&gt;() {}.getType();
  
          ResponseEntity&lt;T&gt; responseEntity = gson.fromJson(reader, type);
  
          return responseEntity;
      }
  </code></pre>
  
  <p>based on <code>ResponseEntity</code> class:</p>
  
  <pre><code>public class ResponseEntity&lt;T&gt; {
  
  private T object;
  private boolean isError;
  private String errorMessage;
  private String successMessage;
  private String technicalErrorMessage;
  
  public ResponseEntity() {
      setSuccessMessage("");
      setError(false);
      setErrorMessage("");
      setTechnicalErrorMessage("");
  }
  
  public T getObject() {
      return object;
  }
  
  public void setObject(T object) {
      this.object = object;
  }
  
  public boolean isError() {
      return isError;
  }
  
  public void setError(boolean error) {
      this.isError = error;
  }
  
  public String getErrorMessage() {
      return errorMessage;
  }
  
  public void setErrorMessage(String errorMessage) {
      this.errorMessage = errorMessage;
  }
  
  public String getTechnicalErrorMessage() {
      return technicalErrorMessage;
  }
  
  public void setTechnicalErrorMessage(String technicalErrorMessage) {
      this.technicalErrorMessage = technicalErrorMessage;
  }
  
  public String getSuccessMessage() {
      return successMessage;
  }
  
  public void setSuccessMessage(String successMessage) {
      this.successMessage = successMessage;
  }}
  </code></pre>
  
  <p>but I am getting result as <code>ResponseEntity&lt;LinkedTreeMap&gt;</code> and the object is map of (<code>Key-&gt;Value</code>) not the actual mapped object that send by the Type <code>ResponseEntity&lt;T&gt;</code>.</p>
  
  <p>The image below is what appeared in the debugger:</p>
  
  <p><a href="https://i.stack.imgur.com/LnO0J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LnO0J.png" alt="image from debugger"></a></p>