Merge pull request #3496 from Kvezon/jersey2-byte-array-deserialize

Support byte[] downloading in Java jersey2 client
This commit is contained in:
wing328 2016-08-02 16:24:40 +08:00 committed by GitHub
commit 7bd37468bc
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.
*/
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
// Handle file downloading.
if (returnType.equals(File.class)) {
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.equals(File.class)) {
// Handle file downloading.
@SuppressWarnings("unchecked")
T file = (T) downloadFileFromResponse(response);
return file;

View File

@ -497,8 +497,15 @@ public class ApiClient {
* Deserialize response body to Java object according to the Content-Type.
*/
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
// Handle file downloading.
if (returnType.equals(File.class)) {
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.equals(File.class)) {
// Handle file downloading.
@SuppressWarnings("unchecked")
T file = (T) downloadFileFromResponse(response);
return file;

View File

@ -497,8 +497,15 @@ public class ApiClient {
* Deserialize response body to Java object according to the Content-Type.
*/
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
// Handle file downloading.
if (returnType.equals(File.class)) {
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.equals(File.class)) {
// Handle file downloading.
@SuppressWarnings("unchecked")
T file = (T) downloadFileFromResponse(response);
return file;