本文整理了Java中io.vertx.ext.web.client.HttpResponse.bodyAsJson()
方法的一些代码示例,展示了HttpResponse.bodyAsJson()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.bodyAsJson()
方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpResponse
类名称:HttpResponse
方法名:bodyAsJson
暂无
代码示例来源:origin: io.vertx/vertx-lang-groovy
public static <R>java.lang.Object bodyAsJson(io.vertx.ext.web.client.HttpResponse<Object> j_receiver, java.lang.Class<java.lang.Object> type) {
return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.bodyAsJson(type));
}
}
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* @param type
* @return the response body decoded as the specified <code>type</code> with the Jackson mapper, or <code>null</code> if a codec other than was used
*/
public <R> R bodyAsJson(Class<R> type) {
R ret = (R)io.vertx.lang.rx.TypeArg.of(type).wrap(delegate.bodyAsJson(io.vertx.lang.rxjava.Helper.unwrap(type)));
return ret;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* @param type
* @return the response body decoded as the specified <code>type</code> with the Jackson mapper, or <code>null</code> if a codec other than was used
*/
public <R> R bodyAsJson(Class<R> type) {
R ret = (R)io.vertx.lang.rx.TypeArg.of(type).wrap(delegate.bodyAsJson(io.vertx.lang.rxjava.Helper.unwrap(type)));
return ret;
}
代码示例来源:origin: vert-x3/vertx-config
/**
* Reads a secret from `path`.
*
* @param path the path
* @param responseHandler the callback invoked with the result
*/
public void read(String path, Handler<AsyncResult<Secret>> responseHandler) {
Objects.requireNonNull(responseHandler);
client.get("/v1/" + Objects.requireNonNull(path))
.putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "No token to access the vault"))
.send(response -> {
if (response.failed()) {
responseHandler.handle(VaultException.toFailure("Unable to access the Vault", response.cause()));
return;
}
HttpResponse<Buffer> result = response.result();
if (result.statusCode() != 200) {
responseHandler.handle(VaultException.toFailure(result.statusMessage(), result.statusCode(),
result.bodyAsString()));
} else {
Secret secret = result.bodyAsJson(Secret.class);
responseHandler.handle(Future.succeededFuture(secret));
}
});
}
代码示例来源:origin: vert-x3/vertx-config
/**
* Write a secret to `path`.
*
* @param path the path
* @param resultHandler the callback invoked with the result
*/
public void write(String path, JsonObject secrets, Handler<AsyncResult<Secret>> resultHandler) {
Objects.requireNonNull(resultHandler);
client.post("/v1/" + Objects.requireNonNull(path))
.putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must be set"))
.sendJsonObject(Objects.requireNonNull(secrets, "The secret must be set"),
ar -> {
if (ar.failed()) {
resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
return;
}
HttpResponse<Buffer> response = ar.result();
if (response.statusCode() == 200 || response.statusCode() == 204) {
resultHandler.handle(Future.succeededFuture(response.bodyAsJson(Secret.class)));
} else {
resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(),
response.bodyAsString()));
}
});
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testResponseUnknownContentTypeBodyAsJsonMapped() throws Exception {
JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
server.requestHandler(req -> req.response().end(expected.encode()));
startServer();
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.bodyAsJson(WineAndCheese.class));
testComplete();
}));
await();
}
内容来源于网络,如有侵权,请联系作者删除!