Support byte[] downloading in Java jersey2 client

This commit is contained in:
Kvezon
2016-08-01 16:33:58 +03:00
parent f5e20b4e88
commit ef526422e9
3 changed files with 27 additions and 6 deletions

View File

@@ -498,8 +498,15 @@ public class ApiClient {
* Deserialize response body to Java object according to the Content-Type. * Deserialize response body to Java object according to the Content-Type.
*/ */
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException { public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
// Handle file downloading. if (response == null || returnType == null) {
if (returnType.equals(File.class)) { return null;
}
if ("byte[]".equals(returnType.toString())) {
// Handle binary response (byte array).
return (T) response.readEntity(byte[].class);
} else if (returnType.equals(File.class)) {
// Handle file downloading.
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T file = (T) downloadFileFromResponse(response); T file = (T) downloadFileFromResponse(response);
return file; return file;

View File

@@ -497,8 +497,15 @@ public class ApiClient {
* Deserialize response body to Java object according to the Content-Type. * Deserialize response body to Java object according to the Content-Type.
*/ */
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException { public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
// Handle file downloading. if (response == null || returnType == null) {
if (returnType.equals(File.class)) { return null;
}
if ("byte[]".equals(returnType.toString())) {
// Handle binary response (byte array).
return (T) response.readEntity(byte[].class);
} else if (returnType.equals(File.class)) {
// Handle file downloading.
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T file = (T) downloadFileFromResponse(response); T file = (T) downloadFileFromResponse(response);
return file; return file;

View File

@@ -497,8 +497,15 @@ public class ApiClient {
* Deserialize response body to Java object according to the Content-Type. * Deserialize response body to Java object according to the Content-Type.
*/ */
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException { public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
// Handle file downloading. if (response == null || returnType == null) {
if (returnType.equals(File.class)) { return null;
}
if ("byte[]".equals(returnType.toString())) {
// Handle binary response (byte array).
return (T) response.readEntity(byte[].class);
} else if (returnType.equals(File.class)) {
// Handle file downloading.
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T file = (T) downloadFileFromResponse(response); T file = (T) downloadFileFromResponse(response);
return file; return file;