src/main/java/com/squareup/connect/ApiClient.java
@SuppressWarnings("unchecked")
  public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
    if (response == null || returnType == null) {
      return null;
    }

    if ("byte[]".equals(returnType.toString())) {
      // Handle binary response (byte array).
      return (T) response.readEntity(byte[].class);
    } else if (returnType.getRawType() == File.class) {
      // Handle file downloading.
      T file = (T) downloadFileFromResponse(response);
      return file;
    }

    String contentType = null;
    List<Object> contentTypes = response.getHeaders().get("Content-Type");
    if (contentTypes != null && !contentTypes.isEmpty())
      contentType = String.valueOf(contentTypes.get(0));
    if (contentType == null)
      throw new ApiException(500, "missing Content-Type in response");

    return response.readEntity(returnType);
  }
/**
   * Deserialize response body to Java object according to the Content-Type.
   * @param <T> Type
   * @param response Response
   * @param returnType Return type
   * @return Deserialize object
   * @throws ApiException API exception
   */
Deserialize response body to Java object according to the Content-Type.
Deserialize response body to Java object according to the Content - Type .
@SuppressWarnings("unchecked")
  public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
    if (response == null || returnType == null) {
      return null;
    }
    if ("byte[]".equals(returnType.toString())) {
      return (T) response.readEntity(byte[].class);
    } else if (returnType.getRawType() == File.class) {
      T file = (T) downloadFileFromResponse(response);
      return file;
    }
    String contentType = null;
    List<Object> contentTypes = response.getHeaders().get("Content-Type");
    if (contentTypes != null && !contentTypes.isEmpty())
      contentType = String.valueOf(contentTypes.get(0));
    if (contentType == null)
      throw new ApiException(500, "missing Content-Type in response");
    return response.readEntity(returnType);
  }
@ SuppressWarnings ( "unchecked" ) public < T > T deserialize ( Response response , GenericType < T > returnType ) throws ApiException { if ( response == null || returnType == null ) { return null ; } if ( "byte[]" . equals ( returnType . toString ( ) ) ) { return ( T ) response . readEntity ( byte [ ] . class ) ; } else if ( returnType . getRawType ( ) == File . class ) { T file = ( T ) downloadFileFromResponse ( response ) ; return file ; } String contentType = null ; List < Object > contentTypes = response . getHeaders ( ) . get ( "Content-Type" ) ; if ( contentTypes != null && ! contentTypes . isEmpty ( ) ) contentType = String . valueOf ( contentTypes . get ( 0 ) ) ; if ( contentType == null ) throw new ApiException ( 500 , "missing Content-Type in response" ) ; return response . readEntity ( returnType ) ; }
Deserialize response body to Java object according to the Content-Type.
Deserialize response body to Java object according to the Content - Type .
// Handle binary response (byte array). // Handle file downloading.