当前位置: 首页>>代码示例>>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;未经允许,请勿转载。