io.vertx.core.json.JsonObject.encodePrettily()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中io.vertx.core.json.JsonObject.encodePrettily()方法的一些代码示例,展示了JsonObject.encodePrettily()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonObject.encodePrettily()方法的具体详情如下:
包路径:io.vertx.core.json.JsonObject
类名称:JsonObject
方法名:encodePrettily

JsonObject.encodePrettily介绍

[英]Encode this JSON object a a string, with whitespace to make the object easier to read by a human, or other sentient organism.
[中]

代码示例

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {
  ProcessorService service = ProcessorService.createProxy(vertx, "vertx.processor");

  JsonObject document = new JsonObject().put("name", "vertx");

  service.process(document, (r) -> {
   if (r.succeeded()) {
    System.out.println(r.result().encodePrettily());
   } else {
    System.out.println(r.cause());
    Failures.dealWithFailure(r.cause());
   }
  });
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {
  someDatabaseService = SomeDatabaseService.createProxy(vertx.getDelegate(), "proxy.address");

  int id = 1;

  // Now you can use your Rx-ified methods.
  Single<JsonObject> single = someDatabaseService.rxGetDataById(id);

  single.subscribe(
   jsonObject -> System.out.println(jsonObject.encodePrettily()),
   throwable -> System.out.println(throwable.getMessage())
  );
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  vertx.createHttpServer().requestHandler(req -> {

   req.bodyHandler(buff -> {
    System.out.println("Receiving user " + buff.toJsonObject().encodePrettily() + " from client ");
    req.response().end();
   });

  }).listen(8080, listenResult -> {
   if (listenResult.failed()) {
    System.out.println("Could not start HTTP server");
    listenResult.cause().printStackTrace();
   } else {
    System.out.println("Server started");
   }
  });
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  vertx.createHttpServer().requestHandler(req -> {

   req.bodyHandler(buff -> {
    System.out.println("Receiving user " + buff.toJsonObject().encodePrettily() + " from client ");
    req.response().end();
   });

  }).listen(8080, listenResult -> {
   if (listenResult.failed()) {
    System.out.println("Could not start HTTP server");
    listenResult.cause().printStackTrace();
   } else {
    System.out.println("Server started");
   }
  });
 }
}

代码示例来源:origin: vert-x3/vertx-examples

@Override
 public void start() throws Exception {

  WebClient client = WebClient.create(vertx);

  client.get(8080, "localhost", "/")
   .as(BodyCodec.jsonObject())
   .send(ar -> {
    if (ar.succeeded()) {
     HttpResponse<JsonObject> response = ar.result();
     System.out.println("Got HTTP response body");
     System.out.println(response.body().encodePrettily());
    } else {
     ar.cause().printStackTrace();
    }
   });
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

@Override
 public void start() throws Exception {
  long time = System.nanoTime();
  vertx.createHttpServer().requestHandler(request -> {
   JsonObject json = new JsonObject();
   json
     .put("clustered", vertx.isClustered())
     .put("metrics", vertx.isMetricsEnabled())
     .put("id", System.getProperty("vertx.id", "no id"))
     .put("conf", config())
     .put("startTime", time);

   if (System.getProperty("foo") != null) {
    json.put("foo", System.getProperty("foo"));
   }

   if (System.getProperty("baz") != null) {
    json.put("baz", System.getProperty("baz"));
   }

   request.response().putHeader("content-type", "application/json").end(json.encodePrettily());
  }).listen(8080);
 }
}

代码示例来源:origin: vert-x3/vertx-examples

private void handleGetProduct(RoutingContext routingContext) {
 String productID = routingContext.request().getParam("productID");
 HttpServerResponse response = routingContext.response();
 if (productID == null) {
  sendError(400, response);
 } else {
  JsonObject product = products.get(productID);
  if (product == null) {
   sendError(404, response);
  } else {
   response.putHeader("content-type", "application/json").end(product.encodePrettily());
  }
 }
}

代码示例来源:origin: eclipse-vertx/vert.x

"  \"myarr\" : [ \"foo\", 123 ]" + Utils.LINE_SEPARATOR +
 "}";
String json = jsonObject.encodePrettily();
assertEquals(expected, json);

代码示例来源:origin: xenv/gushici

private void returnJsonWithCache(RoutingContext routingContext, JsonObject jsonObject) {
  routingContext.response()
    .putHeader("content-type", "application/json; charset=utf-8")
    .end(jsonObject.encodePrettily());
}

代码示例来源:origin: xenv/gushici

private void returnJson(RoutingContext routingContext, JsonObject jsonObject) {
  setCommonHeader(routingContext.response()
    .putHeader("content-type", "application/json; charset=utf-8"))
    .end(jsonObject.encodePrettily());
}

代码示例来源:origin: gravitee-io/gravitee-gateway

@Override
  public void handle(RoutingContext ctx) {
    HttpServerResponse response = ctx.response();
    JsonObject object = new JsonObject()
        .put("counter", syncManager.getCounter())
        .put("lastRefreshAt", syncManager.getLastRefreshAt());

    response.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    response.setChunked(true);
    response.write(object.encodePrettily());
    response.setStatusCode(HttpStatusCode.OK_200);
    response.end();
  }
}

代码示例来源:origin: xenv/gushici

private void returnError(RoutingContext routingContext) {
  JsonObject result = new JsonObject();
  int errorCode = routingContext.statusCode() > 0 ? routingContext.statusCode() : 500;
  // 不懂 Vert.x 为什么 EventBus 和 Web 是两套异常系统
  if (routingContext.failure() instanceof ReplyException) {
    errorCode = ((ReplyException) routingContext.failure()).failureCode();
  }
  result.put("error-code", errorCode);
  if (routingContext.failure() != null) {
    result.put("reason", routingContext.failure().getMessage());
  }
  setCommonHeader(routingContext.response()
    .setStatusCode(errorCode)
    .putHeader("content-type", "application/json; charset=utf-8"))
    .end(result.encodePrettily());
}

代码示例来源:origin: io.vertx/vertx-core

@Override
 public void start() throws Exception {
  long time = System.nanoTime();
  vertx.createHttpServer().requestHandler(request -> {
   JsonObject json = new JsonObject();
   json
     .put("clustered", vertx.isClustered())
     .put("metrics", vertx.isMetricsEnabled())
     .put("id", System.getProperty("vertx.id", "no id"))
     .put("conf", config())
     .put("startTime", time);

   if (System.getProperty("foo") != null) {
    json.put("foo", System.getProperty("foo"));
   }

   if (System.getProperty("baz") != null) {
    json.put("baz", System.getProperty("baz"));
   }

   request.response().putHeader("content-type", "application/json").end(json.encodePrettily());
  }).listen(8080);
 }
}

代码示例来源:origin: io.vertx/vertx-core

"  \"myarr\" : [ \"foo\", 123 ]" + Utils.LINE_SEPARATOR +
 "}";
String json = jsonObject.encodePrettily();
assertEquals(expected, json);

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

@Override
 public String toString() {
  return this.toJson().encodePrettily();
 }
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

@Override
 public String toString() {
  return this.toJson().encodePrettily();
 }
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

protected void internalError(RoutingContext context, Throwable ex) {
 context.response().setStatusCode(500)
  .putHeader("content-type", "application/json")
  .end(new JsonObject().put("error", ex.getMessage()).encodePrettily());
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

protected void notImplemented(RoutingContext context) {
 context.response().setStatusCode(501)
  .putHeader("content-type", "application/json")
  .end(new JsonObject().put("message", "not_implemented").encodePrettily());
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

protected void notFound(RoutingContext context) {
 context.response().setStatusCode(404)
  .putHeader("content-type", "application/json")
  .end(new JsonObject().put("message", "not_found").encodePrettily());
}

代码示例来源:origin: sczyh30/vertx-blueprint-microservice

protected void internalError(RoutingContext context, Throwable ex) {
 context.response().setStatusCode(500)
  .putHeader("content-type", "application/json")
  .end(new JsonObject().put("error", ex.getMessage()).encodePrettily());
}

相关文章