io.vertx.ext.sql.ResultSet.toJson()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(3.6k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中io.vertx.ext.sql.ResultSet.toJson方法的一些代码示例,展示了ResultSet.toJson的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResultSet.toJson方法的具体详情如下:
包路径:io.vertx.ext.sql.ResultSet
类名称:ResultSet
方法名:toJson

ResultSet.toJson介绍

[英]Convert to JSON
[中]转换为JSON

代码示例

代码示例来源:origin: io.vertx/vertx-sql-common

public static void toJson(ResultSet obj, java.util.Map<String, Object> json) {
  if (obj.getColumnNames() != null) {
   JsonArray array = new JsonArray();
   obj.getColumnNames().forEach(item -> array.add(item));
   json.put("columnNames", array);
  }
  if (obj.getNext() != null) {
   json.put("next", obj.getNext().toJson());
  }
  json.put("numColumns", obj.getNumColumns());
  json.put("numRows", obj.getNumRows());
  if (obj.getOutput() != null) {
   json.put("output", obj.getOutput());
  }
  if (obj.getResults() != null) {
   JsonArray array = new JsonArray();
   obj.getResults().forEach(item -> array.add(item));
   json.put("results", array);
  }
  if (obj.getRows() != null) {
   JsonArray array = new JsonArray();
   obj.getRows().forEach(item -> array.add(item));
   json.put("rows", array);
  }
 }
}

代码示例来源:origin: io.vertx/vertx-sql-common

@Test
 public void testJson() {

  JsonObject json = rs.toJson();
  ResultSet rs2 = new ResultSet(json);
  assertEquals(rs, rs2);

 }
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testSimpleConnection(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  if (ar.failed()) {
   context.fail(ar.cause());
   return;
  }
  conn = ar.result();
  conn.query("SELECT 1 AS something", ar2 -> {
   if (ar2.failed()) {
    context.fail(ar2.cause());
   } else {
    ResultSet result = ar2.result();
    context.assertNotNull(result);
    JsonObject expected = new JsonObject()
     .put("columnNames", new JsonArray().add("something"))
     .put("numColumns", 1)
     .put("numRows", 1)
     .put("rows", new JsonArray().add(new JsonObject().put("something", 1)))
     .put("results", new JsonArray().add(new JsonArray().add(1)));
    context.assertEquals(expected, result.toJson());
    async.complete();
   }
  });
 });
}

代码示例来源:origin: io.vertx/vertx-mysql-postgresql-client-jasync

@Test
public void testSimpleConnection(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  if (ar.failed()) {
   context.fail(ar.cause());
   return;
  }
  conn = ar.result();
  conn.query("SELECT 1 AS something", ar2 -> {
   if (ar2.failed()) {
    context.fail(ar2.cause());
   } else {
    ResultSet result = ar2.result();
    context.assertNotNull(result);
    JsonObject expected = new JsonObject()
     .put("columnNames", new JsonArray().add("something"))
     .put("numColumns", 1)
     .put("numRows", 1)
     .put("rows", new JsonArray().add(new JsonObject().put("something", 1)))
     .put("results", new JsonArray().add(new JsonArray().add(1)));
    context.assertEquals(expected, result.toJson());
    async.complete();
   }
  });
 });
}

代码示例来源:origin: vert-x3/vertx-mysql-postgresql-client

@Test
public void testSimpleConnection(TestContext context) {
 Async async = context.async();
 client.getConnection(ar -> {
  if (ar.failed()) {
   context.fail(ar.cause());
   return;
  }
  conn = ar.result();
  conn.query("SELECT 1 AS something", ar2 -> {
   if (ar2.failed()) {
    context.fail(ar2.cause());
   } else {
    ResultSet result = ar2.result();
    context.assertNotNull(result);
    JsonObject expected = new JsonObject()
     .put("columnNames", new JsonArray().add("something"))
     .put("numColumns", 1)
     .put("numRows", 1)
     .put("rows", new JsonArray().add(new JsonObject().put("something", 1)))
     .put("results", new JsonArray().add(new JsonArray().add(1)));
    context.assertEquals(expected, result.toJson());
    async.complete();
   }
  });
 });
}

相关文章