当前位置: 首页>>代码示例>>Java>>正文


Java JsonObject类代码示例

本文整理汇总了Java中io.vertx.core.json.JsonObject的典型用法代码示例。如果您正苦于以下问题:Java JsonObject类的具体用法?Java JsonObject怎么用?Java JsonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonObject类属于io.vertx.core.json包,在下文中一共展示了JsonObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromJson

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
public static void fromJson(JsonObject json, PgConnectOptions obj) {
  if (json.getValue("cachePreparedStatements") instanceof Boolean) {
    obj.setCachePreparedStatements((Boolean)json.getValue("cachePreparedStatements"));
  }
  if (json.getValue("database") instanceof String) {
    obj.setDatabase((String)json.getValue("database"));
  }
  if (json.getValue("host") instanceof String) {
    obj.setHost((String)json.getValue("host"));
  }
  if (json.getValue("password") instanceof String) {
    obj.setPassword((String)json.getValue("password"));
  }
  if (json.getValue("pipeliningLimit") instanceof Number) {
    obj.setPipeliningLimit(((Number)json.getValue("pipeliningLimit")).intValue());
  }
  if (json.getValue("port") instanceof Number) {
    obj.setPort(((Number)json.getValue("port")).intValue());
  }
  if (json.getValue("username") instanceof String) {
    obj.setUsername((String)json.getValue("username"));
  }
}
 
开发者ID:vietj,项目名称:reactive-pg-client,代码行数:24,代码来源:PgConnectOptionsConverter.java

示例2: getShoppingList

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
private void getShoppingList(RoutingContext rc) {
    Single<HttpResponse<Buffer>> list = shopping.get("/shopping").rxSend();

    HttpServerResponse serverResponse = rc.response()
        .setChunked(true);

    list.subscribe(
        response -> {
            JsonObject body = response.bodyAsJsonObject();
            Observable.from(body)
                .flatMap(entry ->
                    retrievePrice(pricer, entry).toObservable())
                .subscribe(
                    product -> writeProductLine(serverResponse, product),
                    rc::fail,
                    serverResponse::end
                );
        },
        rc::fail);
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:21,代码来源:MyShoppingList.java

示例3: getShoppingListWithCB

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
private void getShoppingListWithCB(RoutingContext rc) {
    Single<HttpResponse<Buffer>> list = shopping.get("/shopping").rxSend();

    HttpServerResponse serverResponse = rc.response()
        .setChunked(true);

    list.subscribe(
        response -> {
            JsonObject body = response.bodyAsJsonObject();
            Observable.from(body)
                .flatMap(entry ->
                    circuit.executeWithFallback(
                        future -> retrievePrice(pricer, entry, future),
                        t -> getFallbackPrice(entry)
                    )
                        .rxSetHandler().toObservable())
                .subscribe(
                    product -> writeProductLine(serverResponse, product),
                    rc::fail,
                    serverResponse::end
                );
        },
        rc::fail);
}
 
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:25,代码来源:MyShoppingList.java

示例4: indexHandler

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
private void indexHandler(RoutingContext context) {

    DeliveryOptions options = new DeliveryOptions().addHeader("action", "all-pages"); // <2>

    vertx.eventBus().send(wikiDbQueue, new JsonObject(), options, reply -> {  // <1>
      if (reply.succeeded()) {
        JsonObject body = (JsonObject) reply.result().body();   // <3>
        context.put("title", "Wiki home");
        context.put("pages", body.getJsonArray("pages").getList());
        templateEngine.render(context, "templates", "/index.ftl", ar -> {
          if (ar.succeeded()) {
            context.response().putHeader("Content-Type", "text/html");
            context.response().end(ar.result());
          } else {
            context.fail(ar.cause());
          }
        });
      } else {
        context.fail(reply.cause());
      }
    });
  }
 
开发者ID:dreamzyh,项目名称:vertx-guide-for-java-devs_chinese,代码行数:23,代码来源:HttpServerVerticle.java

示例5: getServiceDiscovery

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
static ServiceDiscovery getServiceDiscovery(io.vertx.core.Vertx vertx) {
  // Discovery settings
  ServiceDiscoveryOptions serviceDiscoveryOptions = new ServiceDiscoveryOptions();
  
  // Redis settings with the standard Redis Backend
  Integer redisPort = Integer.parseInt(Optional.ofNullable(System.getenv("REDIS_PORT")).orElse("6379"));
  String redisHost = Optional.ofNullable(System.getenv("REDIS_HOST")).orElse("127.0.0.1");
  String redisAuth = Optional.ofNullable(System.getenv("REDIS_PASSWORD")).orElse(null);
  String redisRecordsKey = Optional.ofNullable(System.getenv("REDIS_RECORDS_KEY")).orElse("vert.x.ms");    // the redis hash
  
  return ServiceDiscovery.create(
    vertx,
    serviceDiscoveryOptions.setBackendConfiguration(
      new JsonObject()
        .put("host", redisHost)
        .put("port", redisPort)
        .put("auth", redisAuth)
        .put("key", redisRecordsKey)
    ));
}
 
开发者ID:the-big-bang-theory,项目名称:stuart,代码行数:21,代码来源:Parameters.java

示例6: get

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
private void get(String uri, CacheItem<JsonObject> cache, Future<JsonObject> future, Retryable retryable) {
    client.get(HTTPS, ENDPOINT, uri).timeout(5000L).as(BodyCodec.jsonObject()).send(ar -> {
        if (ar.succeeded()) {
            HttpResponse<JsonObject> res = ar.result();
            if (res.statusCode() == OK) {
                future.complete(cache.set(res.body()));
            } else if (res.statusCode() == RATE_LIMIT) {
                retryable.retry(
                        () -> vertx.setTimer(getTimeTillReset(res), timer -> get(uri, cache, future, retryable)),
                        () -> future.fail("Too many retries."));
            } else {
                future.fail("TMDB API returned code: " + res.statusCode() +
                        "; message: " + res.statusMessage());
            }
        } else {
            retryable.retry(
                    () -> vertx.setTimer(DEFAULT_DELAY, timer -> get(uri, cache, future, retryable)),
                    () -> future.fail("Too many failures."));
        }
    });
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:22,代码来源:TmdbServiceImpl.java

示例7: insert

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
/**
 * a插入一条订单记录
 */
public void insert(JsonObject order, Handler<Integer> callback) {
    Integer eid = order.getInteger(EID);
    if (eid == null)
        throw new IllegalArgumentException("Eid in Order object cannot be null!!!");
    String orderId = order.getString(ORDERID);
    if (orderId == null || orderId.length() == 0)
        throw new IllegalArgumentException("OrderId in Order object cannot be null!!!");
    String orderCallback = order.getString(CALLBACK);
    if (orderCallback == null || orderCallback.length() == 0)
        throw new IllegalArgumentException("Callback in Order object cannot be null!!!");
    Integer type = order.getInteger(TYPE);
    if (type == null)
        throw new IllegalArgumentException("Type in Order object cannot be null!!!");
    String sql = "INSERT INTO awp_order (eid,orderId,callback,type,createTime) VALUES (?,?,?,?,NOW())";
    JsonArray params = new JsonArray().add(eid).add(orderId).add(orderCallback).add(type);
    update(sql, params, callback);
}
 
开发者ID:Leibnizhu,项目名称:AlipayWechatPlatform,代码行数:21,代码来源:OrderDao.java

示例8: visit

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
private ConcurrentMap<String, VertxOptions> visit(
        final JsonArray vertxData)
        throws ZeroException {
    final ConcurrentMap<String, VertxOptions> map =
            new ConcurrentHashMap<>();
    final boolean clustered = this.clusterOptions.isEnabled();
    Fn.etJArray(vertxData, JsonObject.class, (item, index) -> {
        // 1. Extract single
        final String name = item.getString(YKEY_NAME);
        // 2. Extract VertxOptions
        final VertxOptions options = this.transformer.transform(item);
        // 3. Check the configuration for cluster sync
        Fn.flingZero(clustered != options.isClustered(), LOGGER,
                ClusterConflictException.class,
                getClass(), name, options.toString());
        // 4. Put the options into map
        map.put(name, options);
    });
    return map;
}
 
开发者ID:silentbalanceyh,项目名称:vertx-zero,代码行数:21,代码来源:VertxVisitor.java

示例9: cannotProvideAdditionalPropertiesInLoan

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
@Test
public void cannotProvideAdditionalPropertiesInLoan()
  throws InterruptedException,
  MalformedURLException,
  TimeoutException,
  ExecutionException {

  UUID id = UUID.randomUUID();

  JsonObject requestWithAdditionalProperty = new LoanRequestBuilder()
    .withId(id)
    .create();

  requestWithAdditionalProperty.put("somethingAdditional", "foo");

  CompletableFuture<JsonErrorResponse> createCompleted = new CompletableFuture();

  client.post(loanStorageUrl(), requestWithAdditionalProperty,
    StorageTestSuite.TENANT_ID, ResponseHandler.jsonErrors(createCompleted));

  JsonErrorResponse response = createCompleted.get(5, TimeUnit.SECONDS);

  assertThat(response.getStatusCode(), is(UNPROCESSABLE_ENTITY));
  assertThat(response.getErrors(), hasSoleMessgeContaining("Unrecognized field"));
}
 
开发者ID:folio-org,项目名称:mod-circulation-storage,代码行数:26,代码来源:LoansApiTest.java

示例10: apiGetPage

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
private void apiGetPage(RoutingContext context) {
  int id = Integer.valueOf(context.request().getParam("id"));
  dbService.rxFetchPageById(id)
    .subscribe(dbObject -> {
      if (dbObject.getBoolean("found")) {
        JsonObject payload = new JsonObject()
          .put("name", dbObject.getString("name"))
          .put("id", dbObject.getInteger("id"))
          .put("markdown", dbObject.getString("content"))
          .put("html", Processor.process(dbObject.getString("content")));
        apiResponse(context, 200, "page", payload);
      } else {
        apiFailure(context, 404, "There is no page with ID " + id);
      }
    }, t -> apiFailure(context, t));
}
 
开发者ID:vert-x3,项目名称:vertx-guide-for-java-devs,代码行数:17,代码来源:HttpServerVerticle.java

示例11: toJSON

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
@Override
public JsonObject toJSON() {
    JsonObject json = new JsonObject();

    //add header information
    json.put("event", this.event);
    json.put("messageID", this.uuid.toString());

    //add message body
    json.put("data", this.data);

    if (!this.ssid.isEmpty()) {
        json.put("ssid", this.ssid);
    }

    return json;
}
 
开发者ID:open-erp-systems,项目名称:erp-frontend,代码行数:18,代码来源:Message.java

示例12: dumbTradingLogic

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
public static Completable dumbTradingLogic(String company, int numberOfShares, io.vertx.workshop.portfolio.reactivex.PortfolioService portfolio, JsonObject quote) {
    if (quote.getString("name").equals(company)) {
        if (TraderUtils.timeToSell()) {
            System.out.println("Trying to sell " + numberOfShares + " " + company);
            return portfolio.rxSell(numberOfShares, quote)
                .doOnSuccess(p -> System.out.println("Sold " + numberOfShares + " of " + company + "!"))
                .doOnError(e -> System.out.println("D'oh, failed to sell " + numberOfShares + " of "
                    + company + ": " + e.getMessage()))
                .toCompletable();
        } else {
            System.out.println("Trying to buy " + numberOfShares + " " + company);
            return portfolio.rxBuy(numberOfShares, quote)
                .doOnSuccess(p -> System.out.println("Bought " + numberOfShares + " of " + company + " !"))
                .doOnError(e -> System.out.println("D'oh, failed to buy " + numberOfShares + " of " + company + " : " + e
                    .getMessage()))
                .toCompletable();
        }
    }

    return Completable.complete();
}
 
开发者ID:cescoffier,项目名称:vertx-kubernetes-workshop,代码行数:22,代码来源:TraderUtils.java

示例13: testInsert

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
@Test
public void testInsert() throws SQLException {
  AtomicInteger counter = new AtomicInteger(0);
  client.handler((event) -> {
    if (!"write".equals(event.getString("type"))) {
      return;
    }
    assertEquals(config().getString("schema"), event.getString("schema"));
    assertEquals("binlog_client_test", event.getString("table"));
    JsonObject json = event.getJsonObject("row");
    Integer id = json.getInteger("id");
    String name = json.getString("name");
    Map.Entry<Integer, String> expectedRow = rows().get(counter.getAndIncrement());
    assertEquals(expectedRow.getKey(), id);
    assertEquals(expectedRow.getValue(), name);
    if (id.equals(lastId())) {
      testComplete();
    }
  });
  insert();
  await();
}
 
开发者ID:guoyu511,项目名称:vertx-mysql-binlog-client,代码行数:23,代码来源:BinlogClientTest.java

示例14: apiUpdatePage

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
@RequiresPermissions("update")
@PUT
@Path("pages/{id}")
public Single<Response> apiUpdatePage(@PathParam("id") String id, 
		@ApiUpdateValid("markdown") JsonObject page,
		@Context HttpServerRequest req,
		@Context Vertx vertx){
	PagesDao dao = (PagesDao) AppGlobals.get().getGlobal("dao");
	return dao.updateExecAsync(new Pages().setId(Integer.valueOf(id)).setContent(page.getString("markdown")))
			.map(res -> {
			    JsonObject event = new JsonObject()
			    	      .put("id", id)
			    	      .put("client", page.getString("client"));
			    vertx.eventBus().publish("page.saved", event);
				return Response.ok(new JsonObject().put("success", true)).build();
			});
}
 
开发者ID:FroMage,项目名称:redpipe,代码行数:18,代码来源:ApiResource.java

示例15: getJsonObject

import io.vertx.core.json.JsonObject; //导入依赖的package包/类
/**
 * Gets value as JsonObject.
 * JsonObjects are converted to JsonObjs.
 * Parses JsonObject and Map types.
 */
@SuppressWarnings("unchecked")
@Override
public JsonObject getJsonObject(String key) {
  Object value = get(key);
  if (value == null) {
    return null;
  }
  if (value instanceof JsonObject) {
    if (value instanceof JsonObj) {
      return ((JsonObj) value);
    }
    return new JsonObj(((JsonObject) value).getMap());
  }
  if (value instanceof Map) {
    return new JsonObj(((Map<String, Object>) value));
  }
  return null;
}
 
开发者ID:kristenkotkas,项目名称:moviediary,代码行数:24,代码来源:JsonObj.java


注:本文中的io.vertx.core.json.JsonObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。