當前位置: 首頁>>代碼示例>>Java>>正文


Java Json.decodeValue方法代碼示例

本文整理匯總了Java中io.vertx.core.json.Json.decodeValue方法的典型用法代碼示例。如果您正苦於以下問題:Java Json.decodeValue方法的具體用法?Java Json.decodeValue怎麽用?Java Json.decodeValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.vertx.core.json.Json的用法示例。


在下文中一共展示了Json.decodeValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addItem

import io.vertx.core.json.Json; //導入方法依賴的package包/類
private void addItem(RoutingContext rc) {
    String body = rc.getBodyAsString();
    if (body != null) {
        Item item = Json.decodeValue(body, Item.class);

        if (item.getQuantity() == 0) {
            redis.hdel("my-shopping-list", item.getName(), res -> {
                if (res.failed()) {
                    rc.fail(res.cause());
                } else {
                    getShoppingList(rc);
                }
            });
        } else {
            redis.hset("my-shopping-list", item.getName(), Integer.toString(item.getQuantity()), res -> {
                if (res.failed()) {
                    rc.fail(res.cause());
                } else {
                    getShoppingList(rc);
                }
            });
        }
    } else {
        rc.response().setStatusCode(400).end();
    }
}
 
開發者ID:cescoffier,項目名稱:vertx-chtijug-2017,代碼行數:27,代碼來源:MyShoppingListVerticle.java

示例2: decodeBodyToObject

import io.vertx.core.json.Json; //導入方法依賴的package包/類
public static <T> T decodeBodyToObject(RoutingContext routingContext, Class<T> clazz) {
  try {
    return Json.decodeValue(routingContext.getBodyAsString("UTF-8"), clazz);
  } catch (DecodeException exception) {
    routingContext.fail(exception);
    return null;
  }
}
 
開發者ID:BillyYccc,項目名稱:vertx-postgresql-starter,代碼行數:9,代碼來源:RestApiUtil.java

示例3: 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);
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:27,代碼來源:BeanTest.java

示例4: decodeFromWire

import io.vertx.core.json.Json; //導入方法依賴的package包/類
@Override
public String[] decodeFromWire(int position, Buffer buffer) {
    int pos = position;

    int length = buffer.getInt(pos);

    // Get JSON string by it`s length
    // Jump 4 because getInt() == 4 bytes
    String jsonStr = buffer.getString(pos+=4, pos+length);

    return Json.decodeValue(jsonStr, String[].class);
}
 
開發者ID:bpark,項目名稱:chlorophytum-semantics,代碼行數:13,代碼來源:StringArrayCodec.java

示例5: decodeFromWire

import io.vertx.core.json.Json; //導入方法依賴的package包/類
@Override
public PersonName decodeFromWire(int position, Buffer buffer) {
    int pos = position;

    int length = buffer.getInt(pos);

    // Get JSON string by it`s length
    // Jump 4 because getInt() == 4 bytes
    String jsonStr = buffer.getString(pos+=4, pos+length);

    return Json.decodeValue(jsonStr, PersonName.class);
}
 
開發者ID:bpark,項目名稱:chlorophytum-semantics,代碼行數:13,代碼來源:PersonNameCodec.java

示例6: handle

import io.vertx.core.json.Json; //導入方法依賴的package包/類
@Override
public void handle(RoutingContext routingContext) {
    String content = routingContext.getBodyAsString();
    final ChatMessage chatMessage = Json.decodeValue(content, ChatMessage.class);

    String messageId = UUID.randomUUID().toString();
    chatMessage.setId(messageId);
    chatMessage.setCreated(System.currentTimeMillis());

    redisClient.hset(MESSAGES, messageId, Json.encode(chatMessage), result -> {});

    vertx.eventBus().send(ChatAddresses.MESSAGES.getAddress(), chatMessage);

    routingContext.response()
            .setStatusCode(201)
            .putHeader("content-type", "application/json; charset=utf-8")
            .end(messageId);
}
 
開發者ID:bpark,項目名稱:chlorophytum-semantics,代碼行數:19,代碼來源:CreateMessageHandler.java

示例7: decodeFromWire

import io.vertx.core.json.Json; //導入方法依賴的package包/類
@Override
public ChatMessage decodeFromWire(int position, Buffer buffer) {
    int pos = position;

    int length = buffer.getInt(pos);

    // Get JSON string by it`s length
    // Jump 4 because getInt() == 4 bytes
    String jsonStr = buffer.getString(pos+=4, pos+length);

    return Json.decodeValue(jsonStr, ChatMessage.class);
}
 
開發者ID:bpark,項目名稱:chlorophytum-semantics,代碼行數:13,代碼來源:ChatMessageCodec.java

示例8: getKeys2

import io.vertx.core.json.Json; //導入方法依賴的package包/類
private void getKeys2(String val, Handler<ExtendedAsyncResult<Collection<String>>> fut) {
  Collection<String> result = new TreeSet<>();
  if (val == null || val.isEmpty()) {
    fut.handle(new Success<>(result));
  } else {
    KeyList keys = Json.decodeValue(val, KeyList.class);

    List<Future> futures = new LinkedList<>();
    for (String k : keys.keys) {
      Future<Void> f = Future.future();
      list.get(k, res -> {
        if (res.failed()) {
          f.handle(Future.failedFuture(res.cause()));
        } else {
          String v = res.result();
          if (v != null) {
            result.add(k);
          }
          f.handle(Future.succeededFuture());
        }
      });
      futures.add(f);
    }
    CompositeFuture.all(futures).setHandler(res -> {
      if (res.failed()) {
        fut.handle(new Failure<>(INTERNAL, res.cause()));
      } else {
        fut.handle(new Success<>(result));
      }
    });
  }
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:33,代碼來源:LockedStringMap.java

示例9: addRecipe

import io.vertx.core.json.Json; //導入方法依賴的package包/類
private void addRecipe(RoutingContext routingContext) {
    String bookId = routingContext.request().getParam("book_id");
    Recipe recipe = Json.decodeValue(routingContext.getBodyAsString(), Recipe.class);
    recipe.setBookId(Long.valueOf(bookId));

    HttpServerResponse response = routingContext.response();
    response.setStatusCode(201)
            .putHeader("content-type", "application/json; charset=utf-8")
            .end(Json.encodePrettily(recipe));
    eventBus.publish("de.nierbeck.vertx.jdbc.write.add", recipe);
}
 
開發者ID:ANierbeck,項目名稱:Karaf-Vertx,代碼行數:12,代碼來源:CookBookServiceVertcl.java

示例10: updateRecipe

import io.vertx.core.json.Json; //導入方法依賴的package包/類
private void updateRecipe(RoutingContext routingContext) {
    String bookId = routingContext.request().getParam("book_id");
    Recipe recipe = Json.decodeValue(routingContext.getBodyAsString(), Recipe.class);
    
    if (recipe.getBookId() != Long.parseLong(bookId)) {
        LOGGER.log(Level.INFO, "something wrong recipe of wrong book id");
    } 
    eventBus.publish("de.nierbeck.vertx.jdbc.write.update", recipe);
}
 
開發者ID:ANierbeck,項目名稱:Karaf-Vertx,代碼行數:10,代碼來源:CookBookServiceVertcl.java

示例11: isValidJson

import io.vertx.core.json.Json; //導入方法依賴的package包/類
/**
 * Checks if is valid json.
 *
 * @param content
 *          the content
 * @return true, if is valid json
 */
protected boolean isValidJson(String content) {
  try {
    Json.decodeValue(content, Object.class);
    return true;
  } catch (Exception e) {
    return false;
  }
}
 
開發者ID:jspare-projects,項目名稱:vertx-jspare,代碼行數:16,代碼來源:APIHandler.java

示例12: putDiscoveryNode

import io.vertx.core.json.Json; //導入方法依賴的package包/類
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));
  });
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:14,代碼來源:InternalModule.java

示例13: createEnv

import io.vertx.core.json.Json; //導入方法依賴的package包/類
private void createEnv(ProxyContext pc, String body,
  Handler<ExtendedAsyncResult<String>> fut) {

  try {
    final EnvEntry pmd = Json.decodeValue(body, EnvEntry.class);
    envManager.add(pmd, res -> {
      if (res.failed()) {
        fut.handle(new Failure<>(res.getType(), res.cause()));
        return;
      }
      final String js = Json.encodePrettily(pmd);
      location(pc, pmd.getName(), null, js, fut);
    });
  } catch (DecodeException ex) {
    fut.handle(new Failure<>(USER, ex));
  }
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:18,代碼來源:InternalModule.java

示例14: addOneTransforms

import io.vertx.core.json.Json; //導入方法依賴的package包/類
/**
 * Transforms specific addOne End Point for Rest API
 * @param routingContext
 *
 * @api {post} /tr 4.Add a transform task
 * @apiVersion 0.1.1
 * @apiName addOneTransforms
 * @apiGroup Transform
 * @apiPermission none
 * @apiDescription This is how we submit or add a transform task to DataFibers.
 * @apiParam   {String}	 None        Json String of task as message body.
 * @apiSuccess (201) {JsonObject[]} connect     The newly added connect task.
 * @apiError    code        The error code.
 * @apiError    message     The error message.
 * @apiErrorExample {json} Error-Response:
 *     HTTP/1.1 409 Conflict
 *     {
 *       "code" : "409",
 *       "message" : "POST Request exception - Conflict."
 *     }
 */
private void addOneTransforms(RoutingContext routingContext) {
    final DFJobPOPJ dfJob = Json.decodeValue(
            HelpFunc.cleanJsonConfig(routingContext.getBodyAsString()), DFJobPOPJ.class);

    dfJob.setStatus(ConstantApp.DF_STATUS.UNASSIGNED.name());
    String mongoId = (dfJob.getId() != null && !dfJob.getId().isEmpty())? dfJob.getId() : new ObjectId().toString();
    dfJob.setConnectUid(mongoId).setId(mongoId).getConnectorConfig().put(ConstantApp.PK_TRANSFORM_CUID, mongoId);

    if(dfJob.getConnectorType().equalsIgnoreCase(ConstantApp.DF_CONNECT_TYPE.TRANSFORM_EXCHANGE_SPARK_SQL.name())) {
        LOG.info("calling spark add = " + dfJob.toJson());
        ProcessorTransformSpark.forwardPostAsAddOne(vertx, wc_spark, dfJob, mongo, COLLECTION,
                spark_livy_server_host, spark_livy_server_port
        );
    } else {
        // Flink refers to KafkaServerHostPort.java
        JsonObject para = HelpFunc.getFlinkJarPara(dfJob,
                this.kafka_server_host_and_port,
                this.schema_registry_host_and_port);

        ProcessorTransformFlink.forwardPostAsSubmitJar(wc_flink, dfJob, mongo, COLLECTION,
                flink_server_host, flink_rest_server_port, flink_jar_id,
                para.getString("allowNonRestoredState"),
                para.getString("savepointPath"),
                para.getString("entryClass"),
                para.getString("parallelism"),
                para.getString("programArgs"));
    }

    mongo.insert(COLLECTION, dfJob.toJson(), r ->
            HelpFunc.responseCorsHandleAddOn(routingContext.response())
                    .setStatusCode(ConstantApp.STATUS_CODE_OK_CREATED)
                    .end(Json.encodePrettily(dfJob)));
    LOG.info(DFAPIMessage.logResponseMessage(1000, dfJob.getId()));
}
 
開發者ID:datafibers-community,項目名稱:df_data_service,代碼行數:56,代碼來源:DFDataProcessor.java

示例15: 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);
}
 
開發者ID:folio-org,項目名稱:okapi,代碼行數:26,代碼來源:BeanTest.java


注:本文中的io.vertx.core.json.Json.decodeValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。