Adjust client response handler to be backwards compatible with older versions of Vert.x (<3.5) (#854)

This commit is contained in:
ccozzolino 2018-08-21 00:12:18 -05:00 committed by William Cheng
parent d374e1c160
commit 2044c36398
2 changed files with 14 additions and 4 deletions

View File

@ -18,6 +18,7 @@ import io.vertx.core.file.FileSystem;
import io.vertx.core.file.OpenOptions;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.json.DecodeException;
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.HttpRequest;
@ -553,7 +554,11 @@ public class ApiClient {
handleFileDownload(httpResponse, handler);
return;
} else {
resultContent = Json.decodeValue(httpResponse.body(), returnType);
try {
resultContent = Json.mapper.readValue(httpResponse.bodyAsString(), returnType);
} catch (Exception e) {
throw new DecodeException("Failed to decode:" + e.getMessage(), e);
}
}
result = Future.succeededFuture(resultContent);
}
@ -597,4 +602,4 @@ public class ApiClient {
auth.applyToParams(queryParams, headerParams);
}
}
}
}

View File

@ -18,6 +18,7 @@ import io.vertx.core.file.FileSystem;
import io.vertx.core.file.OpenOptions;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.json.DecodeException;
import io.vertx.core.json.Json;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.client.HttpRequest;
@ -554,7 +555,11 @@ public class ApiClient {
handleFileDownload(httpResponse, handler);
return;
} else {
resultContent = Json.decodeValue(httpResponse.body(), returnType);
try {
resultContent = Json.mapper.readValue(httpResponse.bodyAsString(), returnType);
} catch (Exception e) {
throw new DecodeException("Failed to decode:" + e.getMessage(), e);
}
}
result = Future.succeededFuture(resultContent);
}
@ -598,4 +603,4 @@ public class ApiClient {
auth.applyToParams(queryParams, headerParams);
}
}
}
}