Java Code Examples for javax.ws.rs.core.GenericType#getRawType()

The following examples show how to use javax.ws.rs.core.GenericType#getRawType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * 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
 */
@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));

  // read the entity stream multiple times
  response.bufferEntity();

  return response.readEntity(returnType);
}
 
Example 2
Source File: ApiClient.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * 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
 */
@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));

  // read the entity stream multiple times
  response.bufferEntity();

  return response.readEntity(returnType);
}
 
Example 3
Source File: ApiClient.java    From connect-java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * 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
 */
@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);
}
 
Example 4
Source File: ApiClient.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
 */
@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));

  return response.readEntity(returnType);
}
 
Example 5
Source File: ApiClient.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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
 */
@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));

  return response.readEntity(returnType);
}
 
Example 6
Source File: WebClient.java    From cxf with Apache License 2.0 3 votes vote down vote up
/**
 * Does HTTP invocation and returns types response object
 * @param httpMethod HTTP method
 * @param body request body, can be null
 * @param responseType generic response type
 * @return typed object, can be null. Response status code and headers
 *         can be obtained too, see Client.getResponse()
 */
public <T> T invoke(String httpMethod, Object body, GenericType<T> responseType) {
    @SuppressWarnings("unchecked")
    Class<T> responseClass = (Class<T>)responseType.getRawType();
    Response r = doInvoke(httpMethod, body, null, responseClass, responseType.getType());
    return castResponse(r, responseClass);
}