forked from loafle/openapi-generator-original
Merge pull request #3496 from Kvezon/jersey2-byte-array-deserialize
Support byte[] downloading in Java jersey2 client
This commit is contained in:
commit
7bd37468bc
@ -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;
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user