Java Code Examples for io.vertx.core.json.JsonArray#addNull()

The following examples show how to use io.vertx.core.json.JsonArray#addNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JDBCStatementHelper.java    From vertx-jdbc-client with Apache License 2.0 6 votes vote down vote up
public io.vertx.ext.sql.ResultSet asList(ResultSet rs) throws SQLException {

    List<String> columnNames = new ArrayList<>();
    ResultSetMetaData metaData = rs.getMetaData();
    int cols = metaData.getColumnCount();
    for (int i = 1; i <= cols; i++) {
      columnNames.add(metaData.getColumnLabel(i));
    }

    List<JsonArray> results = new ArrayList<>();

    while (rs.next()) {
      JsonArray result = new JsonArray();
      for (int i = 1; i <= cols; i++) {
        Object res = convertSqlValue(rs.getObject(i));
        if (res != null) {
          result.add(res);
        } else {
          result.addNull();
        }
      }
      results.add(result);
    }

    return new io.vertx.ext.sql.ResultSet(columnNames, results, null);
  }
 
Example 2
Source File: JDBCCallable.java    From vertx-jdbc-client with Apache License 2.0 6 votes vote down vote up
private JsonArray convertOutputs(CallableStatement statement) throws SQLException {
  JsonArray result = new JsonArray();

  for (int i = 0; i < out.size(); i++) {
    Object var = out.getValue(i);

    if (var != null) {
      Object value = statement.getObject(i + 1);
      if (value == null) {
        result.addNull();
      } else if (value instanceof ResultSet) {
        result.add(helper.asList((ResultSet) value).toJson());
      } else {
        result.add(JDBCStatementHelper.convertSqlValue(value));
      }
    } else {
      result.addNull();
    }
  }

  return result;
}
 
Example 3
Source File: VertxJson.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static void copy(JsonArray array, javax.json.JsonArray origin) {
    for (int i = 0; i < origin.size(); i++) {
        JsonValue value = origin.get(i);
        JsonValue.ValueType kind = value.getValueType();
        switch (kind) {
            case STRING:
                array.add(origin.getString(i));
                break;
            case TRUE:
                array.add(true);
                break;
            case FALSE:
                array.add(false);
                break;
            case NULL:
                array.addNull();
                break;
            case NUMBER:
                JsonNumber number = origin.getJsonNumber(i);
                if (number.isIntegral()) {
                    array.add(number.longValue());
                } else {
                    array.add(number.doubleValue());
                }
                break;
            case ARRAY:
                JsonArray newArray = new JsonArray();
                copy(newArray, origin.getJsonArray(i));
                array.add(newArray);
                break;
            case OBJECT:
                JsonObject newObject = new JsonObject();
                copy(newObject, origin.getJsonObject(i));
                array.add(newObject);
                break;
            default:
                throw new IllegalArgumentException("Unknown JSON Value " + kind);
        }
    }
}
 
Example 4
Source File: Artemis.java    From enmasse with Apache License 2.0 5 votes vote down vote up
private Message doRequestResponse(long timeout, TimeUnit timeUnit, Message message, Object ... parameters) throws TimeoutException {
    JsonArray params = new JsonArray();
    for (Object param : parameters) {
        if (param == null) {
            params.addNull();
        } else {
            params.add(param);
        }
    }

    message.setBody(new AmqpValue(Json.encode(params)));
    return syncRequestClient.request(message, timeout, timeUnit);
}
 
Example 5
Source File: JsonObjectCodec.java    From vertx-mongo-client with Apache License 2.0 5 votes vote down vote up
@Override
protected void add(JsonArray array, Object value) {
  if (value != null) {
    array.add(value);
  } else {
    array.addNull();
  }
}
 
Example 6
Source File: JsArray.java    From vertx-codetrans with Apache License 2.0 4 votes vote down vote up
@CodeTranslate
public void addNull() throws Exception {
  JsonArray arr = new JsonArray();
  arr.addNull();
  JsonTest.o = JsonConverter.toJsonArray(arr);
}