diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 517b6e1c8aa..24de11aedaa 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -498,8 +498,15 @@ public class ApiClient { * Deserialize response body to Java object according to the Content-Type. */ public T deserialize(Response response, GenericType 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; diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java index 06f6d4d899a..617049afbcd 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java @@ -497,8 +497,15 @@ public class ApiClient { * Deserialize response body to Java object according to the Content-Type. */ public T deserialize(Response response, GenericType 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; diff --git a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java index 06f6d4d899a..617049afbcd 100644 --- a/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java @@ -497,8 +497,15 @@ public class ApiClient { * Deserialize response body to Java object according to the Content-Type. */ public T deserialize(Response response, GenericType 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;