本文整理了Java中io.vertx.core.json.Json.encodeToBuffer()
方法的一些代码示例,展示了Json.encodeToBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Json.encodeToBuffer()
方法的具体详情如下:
包路径:io.vertx.core.json.Json
类名称:Json
方法名:encodeToBuffer
[英]Encode a POJO to JSON using the underlying Jackson mapper.
[中]使用底层Jackson映射器将POJO编码为JSON。
代码示例来源:origin: eclipse-vertx/vert.x
/**
* Encode this JSON object as buffer.
*
* @return the buffer encoding.
*/
public Buffer toBuffer() {
return Json.encodeToBuffer(map);
}
代码示例来源: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
@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: io.vertx/vertx-core
/**
* Encode this JSON object as buffer.
*
* @return the buffer encoding.
*/
public Buffer toBuffer() {
return Json.encodeToBuffer(list);
}
代码示例来源:origin: io.vertx/vertx-core
/**
* 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 encodeToBuffer() {
Buffer json = Json.encodeToBuffer("Hello World!");
assertNotNull(json);
// json strings are always UTF8
assertEquals("\"Hello World!\"", json.toString("UTF-8"));
}
代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes
@Test
public void testHttpRecordCreation() {
Service service = getHttpService();
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
assertThat(record.getLocation().getInteger("port")).isEqualTo(8080);
assertThat(record.getLocation().getBoolean("ssl")).isFalse();
}
代码示例来源:origin: vert-x3/vertx-service-discovery
@Test
public void testHttpRecordCreation() {
Service service = getHttpService();
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
assertThat(record.getLocation().getInteger("port")).isEqualTo(8080);
assertThat(record.getLocation().getBoolean("ssl")).isFalse();
}
代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes
@Test
public void testUnknownExternalServiceRecordCreation() {
// JDBC Example
int servicePort = 5432;
Service service = getExternalService(servicePort);
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(JDBCDataSource.TYPE);
assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service");
assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort);
}
代码示例来源:origin: vert-x3/vertx-service-discovery
@Test
public void testUnknownExternalServiceRecordCreation() {
// JDBC Example
int servicePort = 5432;
Service service = getExternalService(servicePort);
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(JDBCDataSource.TYPE);
assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service");
assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort);
}
代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes
@Test
public void testHttpWithSSLExternalServiceRecordCreation() {
int servicePort = 443;
Service service = getExternalService(servicePort);
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service");
assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort);
assertThat(record.getLocation().getBoolean("ssl")).isTrue();
assertThat(record.getLocation().getString("endpoint")).isEqualTo("https://my-external-service:" + servicePort);
}
代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes
@Test
public void testHttpExternalServiceRecordCreation() {
int servicePort = 8080;
Service service = getExternalService(servicePort);
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service");
assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort);
assertThat(record.getLocation().getBoolean("ssl")).isFalse();
assertThat(record.getLocation().getString("endpoint")).isEqualTo("http://my-external-service:" + servicePort);
}
代码示例来源:origin: vert-x3/vertx-service-discovery
@Test
public void testHttpExternalServiceRecordCreation() {
int servicePort = 8080;
Service service = getExternalService(servicePort);
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service");
assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort);
assertThat(record.getLocation().getBoolean("ssl")).isFalse();
assertThat(record.getLocation().getString("endpoint")).isEqualTo("http://my-external-service:" + servicePort);
}
代码示例来源:origin: vert-x3/vertx-service-discovery
@Test
public void testHttpWithSSLExternalServiceRecordCreation() {
int servicePort = 443;
Service service = getExternalService(servicePort);
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
assertThat(record.getLocation().getString("host")).isEqualTo("my-external-service");
assertThat(record.getLocation().getInteger("port")).isEqualTo(servicePort);
assertThat(record.getLocation().getBoolean("ssl")).isTrue();
assertThat(record.getLocation().getString("endpoint")).isEqualTo("https://my-external-service:" + servicePort);
}
代码示例来源:origin: vert-x3/vertx-service-discovery
@Test
public void testRecordCreation() {
ObjectMeta metadata = new ObjectMeta();
metadata.setName("my-service");
metadata.setUid("uuid");
metadata.setNamespace("my-project");
ServiceSpec spec = new ServiceSpec();
ServicePort port = new ServicePort();
port.setTargetPort(new IntOrString(8080));
port.setPort(1524);
spec.setPorts(Collections.singletonList(port));
Service service = new Service();
service.setMetadata(metadata);
service.setSpec(spec);
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(ServiceType.UNKNOWN);
assertThat(record.getLocation().getInteger("port")).isEqualTo(1524);
}
代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes
@Test
public void testRecordCreation() {
ObjectMeta metadata = new ObjectMeta();
metadata.setName("my-service");
metadata.setUid("uuid");
metadata.setNamespace("my-project");
ServiceSpec spec = new ServiceSpec();
ServicePort port = new ServicePort();
port.setTargetPort(new IntOrString(8080));
port.setPort(1524);
spec.setPorts(Collections.singletonList(port));
Service service = new Service();
service.setMetadata(metadata);
service.setSpec(spec);
Record record = KubernetesServiceImporter.createRecord(new JsonObject(Json.encodeToBuffer(service)));
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(ServiceType.UNKNOWN);
assertThat(record.getLocation().getInteger("port")).isEqualTo(1524);
}
代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(ServiceType.UNKNOWN);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(RedisDataSource.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(JDBCDataSource.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(MongoDataSource.TYPE);
代码示例来源:origin: vert-x3/vertx-service-discovery
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(ServiceType.UNKNOWN);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(HttpEndpoint.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(RedisDataSource.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(JDBCDataSource.TYPE);
assertThat(KubernetesServiceImporter.discoveryType(new JsonObject(Json.encodeToBuffer(service)), new Record()))
.isEqualTo(MongoDataSource.TYPE);
代码示例来源:origin: io.vertx/vertx-service-discovery-bridge-kubernetes
@Test
public void testHttpWithSSLRecordCreation() {
Map<String, String> labels = new LinkedHashMap<>();
labels.put("service-type", "http-endpoint");
labels.put("ssl", "true");
ObjectMeta metadata = new ObjectMeta();
metadata.setName("my-service");
metadata.setUid("uuid");
metadata.setNamespace("my-project");
metadata.setLabels(labels);
ServiceSpec spec = new ServiceSpec();
ServicePort port = new ServicePort();
port.setTargetPort(new IntOrString(8080));
port.setPort(8080);
spec.setPorts(Collections.singletonList(port));
Service service = new Service();
service.setMetadata(metadata);
service.setSpec(spec);
Record record = KubernetesServiceImporter.createRecord(Json.encodeToBuffer(service).toJsonObject());
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
assertThat(record.getLocation().getInteger("port")).isEqualTo(8080);
assertThat(record.getLocation().getBoolean("ssl")).isTrue();
}
代码示例来源:origin: vert-x3/vertx-service-discovery
@Test
public void testHttpWithSSLRecordCreation() {
Map<String, String> labels = new LinkedHashMap<>();
labels.put("service-type", "http-endpoint");
labels.put("ssl", "true");
ObjectMeta metadata = new ObjectMeta();
metadata.setName("my-service");
metadata.setUid("uuid");
metadata.setNamespace("my-project");
metadata.setLabels(labels);
ServiceSpec spec = new ServiceSpec();
ServicePort port = new ServicePort();
port.setTargetPort(new IntOrString(8080));
port.setPort(8080);
spec.setPorts(Collections.singletonList(port));
Service service = new Service();
service.setMetadata(metadata);
service.setSpec(spec);
Record record = KubernetesServiceImporter.createRecord(Json.encodeToBuffer(service).toJsonObject());
assertThat(record).isNotNull();
assertThat(record.getName()).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.name")).isEqualTo("my-service");
assertThat(record.getMetadata().getString("kubernetes.namespace")).isEqualTo("my-project");
assertThat(record.getMetadata().getString("kubernetes.uuid")).isEqualTo("uuid");
assertThat(record.getType()).isEqualTo(HttpEndpoint.TYPE);
assertThat(record.getLocation().getInteger("port")).isEqualTo(8080);
assertThat(record.getLocation().getBoolean("ssl")).isTrue();
}
内容来源于网络,如有侵权,请联系作者删除!