本文整理了Java中io.vertx.core.buffer.Buffer.toJsonObject()
方法的一些代码示例,展示了Buffer.toJsonObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.toJsonObject()
方法的具体详情如下:
包路径:io.vertx.core.buffer.Buffer
类名称:Buffer
方法名:toJsonObject
[英]Returns a Json object representation of the Buffer
[中]返回缓冲区的Json对象表示形式
代码示例来源:origin: vert-x3/vertx-examples
public JsonObject getJsonObject() {
return isObject() ? buffer.toJsonObject() : null;
}
代码示例来源: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: eclipse-vertx/vert.x
@Test
public void testToJsonObject() throws Exception {
JsonObject obj = new JsonObject();
obj.put("wibble", "wibble_value");
obj.put("foo", 5);
obj.put("bar", true);
Buffer buff = Buffer.buffer(obj.encode());
assertEquals(obj, buff.toJsonObject());
buff = Buffer.buffer(TestUtils.randomAlphaString(10));
try {
buff.toJsonObject();
fail();
} catch (DecodeException ignore) {
}
}
代码示例来源:origin: vert-x3/vertx-examples
handler.handle(new Batch(payload.toJsonObject()));
break;
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testToJsonArray() throws Exception {
JsonArray arr = new JsonArray();
arr.add("wibble");
arr.add(5);
arr.add(true);
Buffer buff = Buffer.buffer(arr.encode());
assertEquals(arr, buff.toJsonArray());
buff = Buffer.buffer(TestUtils.randomAlphaString(10));
try {
buff.toJsonObject();
fail();
} catch (DecodeException ignore) {
}
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testToJsonObject() throws Exception {
JsonObject obj = new JsonObject();
obj.put("wibble", "wibble_value");
obj.put("foo", 5);
obj.put("bar", true);
Buffer buff = Buffer.buffer(obj.encode());
assertEquals(obj, buff.toJsonObject());
buff = Buffer.buffer(TestUtils.randomAlphaString(10));
try {
buff.toJsonObject();
fail();
} catch (DecodeException ignore) {
}
}
代码示例来源:origin: apache/servicecomb-java-chassis
Buffer action = frame.binaryData();
LOGGER.info("watching config recieved {}", action);
Map<String, Object> mAction = action.toJsonObject().getMap();
if ("CREATE".equals(mAction.get("action"))) {
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* Returns a Json object representation of the Buffer
* @return
*/
public JsonObject toJsonObject() {
JsonObject ret = delegate.toJsonObject();
return ret;
}
代码示例来源:origin: io.vertx/vertx-core
@Test
public void testToJsonArray() throws Exception {
JsonArray arr = new JsonArray();
arr.add("wibble");
arr.add(5);
arr.add(true);
Buffer buff = Buffer.buffer(arr.encode());
assertEquals(arr, buff.toJsonArray());
buff = Buffer.buffer(TestUtils.randomAlphaString(10));
try {
buff.toJsonObject();
fail();
} catch (DecodeException ignore) {
}
}
代码示例来源:origin: apache/servicecomb-java-chassis
private void refreshMembers(MemberDiscovery memberDiscovery) {
if (CONFIG_CENTER_CONFIG.getAutoDiscoveryEnabled()) {
String configCenter = memberDiscovery.getConfigServer();
IpPort ipPort = NetUtils.parseIpPortFromURI(configCenter);
clientMgr.findThreadBindClientPool().runOnContext(client -> {
HttpClientRequest request =
client.get(ipPort.getPort(), ipPort.getHostOrIp(), uriConst.MEMBERS, rsp -> {
if (rsp.statusCode() == HttpResponseStatus.OK.code()) {
rsp.bodyHandler(buf -> {
memberDiscovery.refreshMembers(buf.toJsonObject());
});
}
});
SignRequest signReq = createSignRequest(request.method().toString(),
configCenter + uriConst.MEMBERS,
new HashMap<>(),
null);
if (ConfigCenterConfig.INSTANCE.getToken() != null) {
request.headers().add("X-Auth-Token", ConfigCenterConfig.INSTANCE.getToken());
}
authHeaderProviders.forEach(provider -> request.headers()
.addAll(provider.getSignAuthHeaders(signReq)));
request.exceptionHandler(e -> {
LOGGER.error("Fetch member from {} failed. Error message is [{}].", configCenter, e.getMessage());
});
request.end();
});
}
}
代码示例来源:origin: vert-x3/vertx-kafka-client
@Override
public JsonObject deserialize(String topic, byte[] data) {
if (data == null)
return null;
return Buffer.buffer(data).toJsonObject();
}
代码示例来源:origin: io.vertx/vertx-config
@Override
public void process(Vertx vertx, JsonObject configuration, Buffer input, Handler<AsyncResult<JsonObject>> handler) {
try {
JsonObject json = input.toJsonObject();
if (json == null) {
json = new JsonObject();
}
handler.handle(Future.succeededFuture(json));
} catch (Exception e) {
handler.handle(Future.failedFuture(e));
}
}
代码示例来源:origin: vert-x3/vertx-config
@Override
public void process(Vertx vertx, JsonObject configuration, Buffer input, Handler<AsyncResult<JsonObject>> handler) {
try {
JsonObject json = input.toJsonObject();
if (json == null) {
json = new JsonObject();
}
handler.handle(Future.succeededFuture(json));
} catch (Exception e) {
handler.handle(Future.failedFuture(e));
}
}
代码示例来源:origin: eclipse/hono
/**
* Parses a message's body into a JSON object.
*
* @param msg The AMQP 1.0 message to parse the body of.
* @return The message body parsed into a JSON object or {@code null} if the message does not have a <em>Data</em>
* nor an <em>AmqpValue</em> section.
* @throws NullPointerException if the message is {@code null}.
* @throws DecodeException if the payload cannot be parsed into a JSON object.
*/
public static JsonObject getJsonPayload(final Message msg) {
final Buffer buffer = getPayload(msg);
return buffer != null ? buffer.toJsonObject() : null;
}
代码示例来源:origin: silentbalanceyh/vertx-zero
/**
* Final hitted
*
* @param data
* @return
*/
public static Envelop consume(final IpcData data) {
final JsonObject json = data.getData().toJsonObject();
return build(json);
}
代码示例来源:origin: org.swisspush.gateleen/gateleen-queue
private QueueCircuitState extractStatusFromBody(Buffer bodyBuffer) {
if (StringUtils.isNotEmptyTrimmed(bodyBuffer.toString())) {
try {
JsonObject obj = bodyBuffer.toJsonObject();
return QueueCircuitState.fromString(obj.getString(STATUS), null);
} catch (Exception ex) {
return null;
}
}
return null;
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testSendJsonObjectBody() throws Exception {
JsonObject body = new JsonObject().put("wine", "Chateauneuf Du Pape").put("cheese", "roquefort");
testSendBody(body, (contentType, buff) -> {
assertEquals("application/json", contentType);
assertEquals(body, buff.toJsonObject());
});
}
代码示例来源:origin: georocket/georocket
private void checkGeoJsonResponse(HttpClientResponse response, TestContext context, Handler<JsonObject> handler) {
response.bodyHandler(body -> {
JsonObject returned = body.toJsonObject();
context.assertNotNull(returned);
context.assertTrue(returned.containsKey("geometries"));
handler.handle(returned);
});
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testSendJsonPojoBody() throws Exception {
testSendBody(new WineAndCheese().setCheese("roquefort").setWine("Chateauneuf Du Pape"),
(contentType, buff) -> {
assertEquals("application/json", contentType);
assertEquals(new JsonObject().put("wine", "Chateauneuf Du Pape").put("cheese", "roquefort"), buff.toJsonObject());
});
}
内容来源于网络,如有侵权,请联系作者删除!