title: Not Able to Cast the Object to Custom Object
body: <p>I have the APIResponse class which extends the Object class like <code>&lt;T extends Object&gt;</code> but while getting the response body from the rest template getting the data into the Object class, not to the Book class.</p>
  
  <p>If I try to fetch the data into the Book class it gives the null. </p>
  
  <p><strong>I have tried</strong> typecasting the response in The Book Object but no success.
  ex.<code>ApiResponse&lt;Book&gt;</code>.</p>
  
  <pre class="lang-java prettyprint-override"><code>public void testCreate(){
      ClientHttpRequestFactory factory = new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory());
      RestTemplate restTemplate = new RestTemplate(factory);
      BookDto bookDto = new BookDto("Pranav","dummy","dummy");
      String url = "http://localhost:9090/books";
  
      HttpEntity&lt;BookDto&gt; httpEntity = getHttpEntity(bookDto);
  
      ResponseEntity&lt;Object&gt; book = restTemplate.exchange(url,HttpMethod.POST,httpEntity,Object.class);
  
          //Able to Get the response body in Object but if I try to change it to the Book the response body is coming null.
    }
  
      private HttpEntity&lt;BookDto&gt; getHttpEntity(BookDto bookDto) {
          HttpHeaders headers = new HttpHeaders();
          headers.setContentType(MediaType.APPLICATION_JSON);
          headers.set("Accept",MediaType.APPLICATION_JSON_VALUE);
          return new HttpEntity&lt;&gt;(bookDto,headers);
      }
  
  @JsonInclude(JsonInclude.Include.NON_NULL)
  public class APIResponse&lt;T extends Object&gt; implements Serializable {
  
    /**
     * status &amp; message fields have not setter. They are assigned value when
     * initial by APIStatus parameter
     */
    private int status;
    private String message;
    private T data;
  
    public APIResponse(APIStatus apiStatus, T data) {
  
      if (apiStatus == null) {
        throw new IllegalArgumentException("APIStatus must not be null");
      }
  
      this.status = apiStatus.getCode();
      this.message = apiStatus.getDescription();
      this.data = data;
    }
  
    public int getStatus() {
      return status;
    }
  
    public String getMessage() {
      return message;
    }
  
    public T getData() {
      return data;
    }
  
    public void setData(T data) {
      this.data = data;
    }
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>public enum APIStatus {
    // Common status
    OK(200, null);
    private final int code;
    private final String description;
  
    private APIStatus(int s, String v) {
      code = s;
      description = v;
    }
  
    public int getCode() {
      return code;
    }
  
    public String getDescription() {
      return description;
    }
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class ResponseUtil {
  
    private APIResponse&lt;Book&gt; createResponse(APIStatus apiStatus, Object data) {
      return new APIResponse(apiStatus, data);
    }
    // base method
    public ResponseEntity&lt;APIResponse&lt;Book&gt;&gt; buildResponse(APIStatus apiStatus, Object data, HttpStatus httpStatus) {
      return new ResponseEntity(createResponse(apiStatus, data), httpStatus);
    }
  
    public ResponseEntity&lt;APIResponse&lt;Book&gt;&gt; successResponse(Object data) {
      return buildResponse(APIStatus.OK, data, HttpStatus.OK);
    }
  }
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>@RestController
  public class BookController {
  
    @Autowired
    BookService bookService;
  
    @Autowired
    protected ResponseUtil responseUtil;
  
    @GetMapping("/books")
    ResponseEntity&lt;APIResponse&lt;Book&gt;&gt; read(){
      return responseUtil.successResponse(bookService.findAll());
    }
  }
  </code></pre>
  
  <p>I expect the response body result into the Book Object, not to the General Object class.</p>