io.vertx.core.json.Json类的使用及代码示例

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

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

Json介绍

暂无

代码示例

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

/**
 * Encode the JSON array to a string
 *
 * @return the string encoding
 */
public String encode() {
 return Json.encode(list);
}

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

private void fromJson(String json) {
 map = Json.decodeValue(json, Map.class);
}

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

/**
 * Encode this JSON object a a string, with whitespace to make the object easier to read by a human, or other
 * sentient organism.
 *
 * @return the pretty string encoding.
 */
public String encodePrettily() {
 return Json.encodePrettily(map);
}

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

@Test
public void testGenericDecoding() {
 Pojo original = new Pojo();
 original.value = "test";
 String json = Json.encode(Collections.singletonList(original));
 List<Pojo> correct;
 correct = Json.decodeValue(json, new TypeReference<List<Pojo>>() {});
 assertTrue(((List)correct).get(0) instanceof Pojo);
 assertEquals(original.value, correct.get(0).value);
 // same must apply if instead of string we use a buffer
 correct = Json.decodeValue(Buffer.buffer(json, "UTF8"), new TypeReference<List<Pojo>>() {});
 assertTrue(((List)correct).get(0) instanceof Pojo);
 assertEquals(original.value, correct.get(0).value);
 List incorrect = Json.decodeValue(json, List.class);
 assertFalse(incorrect.get(0) instanceof Pojo);
 assertTrue(incorrect.get(0) instanceof Map);
 assertEquals(original.value, ((Map)(incorrect.get(0))).get("value"));
}

代码示例来源:origin: cescoffier/my-vertx-first-app

private void addOne(RoutingContext routingContext) {
 final Whisky whisky = Json.decodeValue(routingContext.getBodyAsString(),
   Whisky.class);
 mongo.insert(COLLECTION, whisky.toJson(), r ->
   routingContext.response()
     .setStatusCode(201)
     .putHeader("content-type", "application/json; charset=utf-8")
     .end(Json.encodePrettily(whisky.setId(r.result()))));
}

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

/**
 * Encode this JSON object as buffer.
 *
 * @return the buffer encoding.
 */
public Buffer toBuffer() {
 return Json.encodeToBuffer(map);
}

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

@Test
public void testGenericDecoding() {
 Pojo original = new Pojo();
 original.value = "test";
 String json = Json.encode(Collections.singletonList(original));
 List<Pojo> correct;
 correct = Json.decodeValue(json, new TypeReference<List<Pojo>>() {});
 assertTrue(((List)correct).get(0) instanceof Pojo);
 assertEquals(original.value, correct.get(0).value);
 // same must apply if instead of string we use a buffer
 correct = Json.decodeValue(Buffer.buffer(json, "UTF8"), new TypeReference<List<Pojo>>() {});
 assertTrue(((List)correct).get(0) instanceof Pojo);
 assertEquals(original.value, correct.get(0).value);
 List incorrect = Json.decodeValue(json, List.class);
 assertFalse(incorrect.get(0) instanceof Pojo);
 assertTrue(incorrect.get(0) instanceof Map);
 assertEquals(original.value, ((Map)(incorrect.get(0))).get("value"));
}

代码示例来源:origin: folio-org/okapi

private void putDiscoveryNode(String id, String body,
 Handler<ExtendedAsyncResult<String>> fut) {
 logger.debug("Int: putDiscoveryNode: " + id + " " + body);
 final NodeDescriptor nd = Json.decodeValue(body, NodeDescriptor.class);
 discoveryManager.updateNode(id, nd, res -> {
  if (res.failed()) {
   fut.handle(new Failure<>(res.getType(), res.cause()));
   return;
  }
  final String s = Json.encodePrettily(res.result());
  fut.handle(new Success<>(s));
 });
}

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

/**
 * Encode this JSON object as buffer.
 *
 * @return the buffer encoding.
 */
public Buffer toBuffer() {
 return Json.encodeToBuffer(list);
}

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

/**
 * Encode this JSON object as a string.
 *
 * @return the string encoding.
 */
public String encode() {
 return Json.encode(map);
}

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

private void fromBuffer(Buffer buf) {
 list = Json.decodeValue(buf, List.class);
}

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

/**
 * Encode the JSON array prettily as a string
 *
 * @return the string encoding
 */
public String encodePrettily() {
 return Json.encodePrettily(list);
}

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

@Test
public void encodeToBuffer() {
 Buffer json = Json.encodeToBuffer("Hello World!");
 assertNotNull(json);
 // json strings are always UTF8
 assertEquals("\"Hello World!\"", json.toString("UTF-8"));
}

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

@Test
public void encodeCustomTypeInstant() {
 Instant now = Instant.now();
 String json = Json.encode(now);
 assertNotNull(json);
 // the RFC is one way only
 Instant decoded = Instant.from(ISO_INSTANT.parse(json.substring(1, json.length() - 1)));
 assertEquals(now, decoded);
}

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

private void fromBuffer(Buffer buf) {
 map = Json.decodeValue(buf, Map.class);
}

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

/**
 * Encode this JSON object a a string, with whitespace to make the object easier to read by a human, or other
 * sentient organism.
 *
 * @return the pretty string encoding.
 */
public String encodePrettily() {
 return Json.encodePrettily(map);
}

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

/**
 * Encode this JSON object as buffer.
 *
 * @return the buffer encoding.
 */
public Buffer toBuffer() {
 return Json.encodeToBuffer(map);
}

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

@Test
public void encodeCustomTypeBinaryNull() {
 byte[] data = null;
 String json = Json.encode(data);
 assertNotNull(json);
 assertEquals("null", json);
}

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

private void fromJson(String json) {
 list = Json.decodeValue(json, List.class);
}

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

/**
 * Encode the JSON array prettily as a string
 *
 * @return the string encoding
 */
public String encodePrettily() {
 return Json.encodePrettily(list);
}

相关文章