本文整理汇总了Java中io.vertx.core.json.Json.encodePrettily方法的典型用法代码示例。如果您正苦于以下问题:Java Json.encodePrettily方法的具体用法?Java Json.encodePrettily怎么用?Java Json.encodePrettily使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vertx.core.json.Json
的用法示例。
在下文中一共展示了Json.encodePrettily方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDeploymentDescriptor1
import io.vertx.core.json.Json; //导入方法依赖的package包/类
@Test
public void testDeploymentDescriptor1() {
int fail = 0;
final String docSampleDeployment = "{" + LS
+ " \"srvcId\" : \"sample-module-1\"," + LS
+ " \"descriptor\" : {" + LS
+ " \"exec\" : "
+ "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"," + LS
+ " \"env\" : [ {" + LS
+ " \"name\" : \"helloGreeting\"," + LS
+ " \"value\" : \"hej\"" + LS
+ " } ]" + LS
+ " }" + LS
+ "}";
try {
final DeploymentDescriptor md = Json.decodeValue(docSampleDeployment,
DeploymentDescriptor.class);
String pretty = Json.encodePrettily(md);
assertEquals(docSampleDeployment, pretty);
} catch (DecodeException ex) {
ex.printStackTrace();
fail = 400;
}
assertEquals(0, fail);
}
示例2: checkThatWeCanAdd
import io.vertx.core.json.Json; //导入方法依赖的package包/类
@Test
public void checkThatWeCanAdd(TestContext context) {
Async async = context.async();
final String json = Json.encodePrettily(new Article("Some title", "Some url"));
vertx.createHttpClient().post(port, "localhost", "/api/articles")
.putHeader("Content-Type", "application/json")
.putHeader("Content-Length", Integer.toString(json.length()))
.handler(response -> {
context.assertEquals(response.statusCode(), 201);
context.assertTrue(response.headers().get("content-type").contains("application/json"));
response.bodyHandler(body -> {
Article article = Json.decodeValue(body.toString(), Article.class);
context.assertEquals(article.getTitle(), "Some title");
context.assertEquals(article.getUrl(), "Some url");
context.assertNotNull(article.getId());
async.complete();
});
})
.write(json)
.end();
}
示例3: checkThatWeCanAdd
import io.vertx.core.json.Json; //导入方法依赖的package包/类
@Test
public void checkThatWeCanAdd(TestContext context) {
Async async = context.async();
final String json = Json.encodePrettily(new DFJobPOPJ("Jameson", "Ireland","Register"));
vertx.createHttpClient().post(port, "localhost", "/api/df")
.putHeader("content-type", "application/json")
.putHeader("content-length", Integer.toString(json.length()))
.handler(response -> {
context.assertEquals(response.statusCode(), 201);
context.assertTrue(response.headers().get("content-type").contains("application/json"));
response.bodyHandler(body -> {
final DFJobPOPJ DFJob = Json.decodeValue(body.toString(), DFJobPOPJ.class);
context.assertEquals(DFJob.getName(), "Jameson");
context.assertEquals(DFJob.getConnectUid(), "Ireland");
context.assertNotNull(DFJob.getId());
async.complete();
});
})
.write(json)
.end();
}
示例4: testDeploymentDescriptor3
import io.vertx.core.json.Json; //导入方法依赖的package包/类
@Test
public void testDeploymentDescriptor3() {
int fail = 0;
final String docSampleDeployment = "{" + LS
+ " \"srvcId\" : \"sample-module-1\"," + LS
+ " \"descriptor\" : {" + LS
+ " \"exec\" : "
+ "\"java -Dport=%p -jar ../okapi-test-module/target/okapi-test-module-fat.jar\"" + LS
+ " }" + LS
+ "}";
try {
final DeploymentDescriptor md = Json.decodeValue(docSampleDeployment,
DeploymentDescriptor.class);
String pretty = Json.encodePrettily(md);
assertEquals(docSampleDeployment, pretty);
} catch (DecodeException ex) {
ex.printStackTrace();
fail = 400;
}
assertEquals(0, fail);
}
示例5: testDeploymentDescriptor4
import io.vertx.core.json.Json; //导入方法依赖的package包/类
@Test
public void testDeploymentDescriptor4() {
int fail = 0;
final String docSampleDeployment = "{" + LS
+ " \"srvcId\" : \"sample-module-1\"," + LS
+ " \"descriptor\" : {" + LS
+ " \"dockerImage\" : \"my-image\"," + LS
+ " \"dockerArgs\" : {" + LS
+ " \"Hostname\" : \"localhost\"," + LS
+ " \"User\" : \"nobody\"" + LS
+ " }" + LS
+ " }" + LS
+ "}";
try {
final DeploymentDescriptor md = Json.decodeValue(docSampleDeployment,
DeploymentDescriptor.class);
String pretty = Json.encodePrettily(md);
assertEquals(docSampleDeployment, pretty);
} catch (DecodeException ex) {
ex.printStackTrace();
fail = 400;
}
assertEquals(0, fail);
}
示例6: post
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void post(URL url,
Object body,
String tenantId,
Handler<HttpClientResponse> responseHandler) {
HttpClientRequest request = client.postAbs(url.toString(), responseHandler);
request.headers().add("Accept","application/json, text/plain");
request.headers().add("Content-type","application/json");
if(tenantId != null) {
request.headers().add(TENANT_HEADER, tenantId);
}
if(body != null) {
String encodedBody = Json.encodePrettily(body);
System.out.println(String.format("POST %s, Request: %s",
url.toString(), encodedBody));
request.end(encodedBody);
}
else {
request.end();
}
}
示例7: post
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void post(URL url,
Object body,
String tenantId,
String userId,
Handler<HttpClientResponse> responseHandler) {
HttpClientRequest request = client.postAbs(url.toString(), responseHandler);
request.headers().add("Accept","application/json, text/plain");
request.headers().add("Content-type","application/json");
if(tenantId != null) {
request.headers().add(TENANT_HEADER, tenantId);
}
if(userId != null) {
request.headers().add(USERID_HEADER, userId);
}
if(body != null) {
String encodedBody = Json.encodePrettily(body);
System.out.println(String.format("POST %s, Request: %s",
url.toString(), encodedBody));
log.debug(String.format("POST %s, Request: %s",
url.toString(), encodedBody));
request.end(encodedBody);
}
else {
request.end();
}
}
示例8: put
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void put(URL url,
Object body,
String tenantId,
String userId,
Handler<HttpClientResponse> responseHandler) {
HttpClientRequest request = client.putAbs(url.toString(), responseHandler);
request.headers().add("Accept","application/json, text/plain");
request.headers().add("Content-type","application/json");
if(tenantId != null) {
request.headers().add(TENANT_HEADER, tenantId);
}
if(userId != null){
request.headers().add(USERID_HEADER, userId);
}
String encodedBody = Json.encodePrettily(body);
System.out.println(String.format("PUT %s, Request: %s",
url.toString(), encodedBody));
log.debug(String.format("PUT %s, Request: %s",
url.toString(), encodedBody));
request.end(encodedBody);
}
示例9: handleCreateTodo
import io.vertx.core.json.Json; //导入方法依赖的package包/类
private void handleCreateTodo(RoutingContext context) {
final Todo todo = wrapObject(getTodoFromJson
(context.getBodyAsString()), context);
final String encoded = Json.encodePrettily(todo);
redis.hset(REDIS_TODO_KEY, String.valueOf(todo.getId()),
encoded, res -> {
if (res.succeeded())
context.response()
.setStatusCode(201)
.putHeader("content-type", "application/json; charset=utf-8")
.end(encoded);
else
sendError(503, context.response());
});
}
示例10: add
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void add(T env, String id, Handler<ExtendedAsyncResult<Void>> fut) {
JsonObject jq = new JsonObject().put("_id", id);
String s = Json.encodePrettily(env);
JsonObject document = new JsonObject(s);
encode(document, id);
UpdateOptions options = new UpdateOptions().setUpsert(true);
cli.updateCollectionWithOptions(collection, jq, new JsonObject().put("$set", document), options, res -> {
if (res.succeeded()) {
fut.handle(new Success<>());
} else {
fut.handle(new Failure<>(INTERNAL, res.cause()));
}
});
}
示例11: insert
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void insert(T md, String id, Handler<ExtendedAsyncResult<Void>> fut) {
String s = Json.encodePrettily(md);
JsonObject document = new JsonObject(s);
encode(document, id);
cli.insert(collection, document, res -> {
if (res.succeeded()) {
fut.handle(new Success<>());
} else {
fut.handle(new Failure<>(INTERNAL, res.cause()));
}
});
}
示例12: sendMessageToWebService
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void sendMessageToWebService(WebMessage webMessage) {
transcription.add(webMessage);
String encodePrettily = Json.encodePrettily(webMessage);
logger.debug("Sending to WS Client: " + encodePrettily);
Buffer b = Buffer.buffer(encodePrettily);
sockJSSocket.write(b);
logger.debug("Send complete");
}
示例13: post
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public void post(URL url,
Object body,
Handler<HttpClientResponse> responseHandler) {
HttpClientRequest request = client.postAbs(url.toString(), responseHandler);
request.headers().add("Accept","application/json, text/plain");
request.headers().add("Content-type","application/json");
request.headers().add(OKAPI_URL_HEADER, okapiUrl.toString());
addMandatoryHeaders(request);
request.setTimeout(5000);
request.exceptionHandler(exception -> {
this.exceptionHandler.accept(exception);
});
if(body != null) {
String encodedBody = Json.encodePrettily(body);
System.out.println(String.format("POST %s, Request: %s",
url.toString(), encodedBody));
request.end(encodedBody);
}
else {
request.end();
}
}
示例14: toJson
import io.vertx.core.json.Json; //导入方法依赖的package包/类
public String toJson() {
if(response == null || response instanceof Void) return null;
if(response instanceof JsonObject) return ((JsonObject) response).encodePrettily();
if(response instanceof JsonArray) return ((JsonArray) response).encodePrettily();
return Json.encodePrettily(response);
}
示例15: tenantPerms
import io.vertx.core.json.Json; //导入方法依赖的package包/类
/**
* Helper to make the tenantPermissions call for one module. Used from
* ead3RealoadPerms and ead4Permissions.
*/
private void tenantPerms(Tenant tenant, ModuleDescriptor mdTo,
ModuleDescriptor permsModule, ProxyContext pc,
Handler<ExtendedAsyncResult<Void>> fut) {
pc.debug("Loading permissions for " + mdTo.getName()
+ " (using " + permsModule.getName() + ")");
String moduleTo = mdTo.getId();
PermissionList pl = new PermissionList(moduleTo, mdTo.getPermissionSets());
String pljson = Json.encodePrettily(pl);
pc.debug("tenantPerms Req: " + pljson);
InterfaceDescriptor permInt = permsModule.getSystemInterface("_tenantPermissions");
String permPath = "";
List<RoutingEntry> routingEntries = permInt.getAllRoutingEntries();
if (!routingEntries.isEmpty()) {
for (RoutingEntry re : routingEntries) {
if (re.match(null, "POST")) {
permPath = re.getPath();
if (permPath == null || permPath.isEmpty()) {
permPath = re.getPathPattern();
}
}
}
}
if (permPath == null || permPath.isEmpty()) {
fut.handle(new Failure<>(USER,
"Bad _tenantPermissions interface in module " + permsModule.getId()
+ ". No path to POST to"));
return;
}
pc.debug("tenantPerms: " + permsModule.getId() + " and " + permPath);
proxyService.callSystemInterface(tenant.getId(),
permsModule.getId(), permPath, pljson, pc, cres -> {
if (cres.failed()) {
fut.handle(new Failure<>(cres.getType(), cres.cause()));
} else {
pc.debug("tenantPerms request to " + permsModule.getName()
+ " succeeded for module " + moduleTo + " and tenant " + tenant.getId());
fut.handle(new Success<>());
}
});
}