本文整理了Java中io.vertx.core.json.JsonArray.add()
方法的一些代码示例,展示了JsonArray.add()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonArray.add()
方法的具体详情如下:
包路径:io.vertx.core.json.JsonArray
类名称:JsonArray
方法名:add
[英]Add another JSON array to the JSON array.
[中]将另一个JSON数组添加到JSON数组。
代码示例来源:origin: eclipse-vertx/vert.x
private void addToHA(String deploymentID, String verticleName, DeploymentOptions deploymentOptions) {
String encoded;
synchronized (haInfo) {
JsonObject verticleConf = new JsonObject().put("dep_id", deploymentID);
verticleConf.put("verticle_name", verticleName);
verticleConf.put("options", deploymentOptions.toJson());
JsonArray haMods = haInfo.getJsonArray("verticles");
haMods.add(verticleConf);
encoded = haInfo.encode();
clusterMap.put(nodeID, encoded);
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testMapReplaceIfPresentJsonArray() {
testMapReplaceIfPresent(new JsonArray().add("foo").add(2), new JsonArray().add("uihwqduh").add(false),
new JsonArray().add("qqddq").add(true));
}
代码示例来源:origin: eclipse-vertx/vert.x
static void toJson(PemTrustOptions obj, java.util.Map<String, Object> json) {
if (obj.getCertPaths() != null) {
JsonArray array = new JsonArray();
obj.getCertPaths().forEach(item -> array.add(item));
json.put("certPaths", array);
}
if (obj.getCertValues() != null) {
JsonArray array = new JsonArray();
obj.getCertValues().forEach(item -> array.add(java.util.Base64.getEncoder().encodeToString(item.getBytes())));
json.put("certValues", array);
}
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testEncode() throws Exception {
jsonArray.add("foo");
jsonArray.add(123);
jsonArray.add(1234l);
jsonArray.add(1.23f);
jsonArray.add(2.34d);
jsonArray.add(true);
byte[] bytes = TestUtils.randomByteArray(10);
jsonArray.add(bytes);
jsonArray.addNull();
jsonArray.add(new JsonObject().put("foo", "bar"));
jsonArray.add(new JsonArray().add("foo").add(123));
String strBytes = Base64.getEncoder().encodeToString(bytes);
String expected = "[\"foo\",123,1234,1.23,2.34,true,\"" + strBytes + "\",null,{\"foo\":\"bar\"},[\"foo\",123]]";
String json = jsonArray.encode();
assertEquals(expected, json);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testSize() {
jsonArray.add("wibble");
jsonArray.add(true);
jsonArray.add(123);
assertEquals(3, jsonArray.size());
}
代码示例来源:origin: vert-x3/vertx-examples
private void listAlbums(Message<JsonObject> msg) {
// issue a find command to mongo to fetch all documents from the "albums" collection.
mongo.find("albums", new JsonObject(), lookup -> {
// error handling
if (lookup.failed()) {
msg.fail(500, lookup.cause().getMessage());
return;
}
// now convert the list to a JsonArray because it will be easier to encode the final object as the response.
final JsonArray json = new JsonArray();
for (JsonObject o : lookup.result()) {
json.add(o);
}
msg.reply(json);
});
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
// A simple backend
vertx.eventBus().<JsonObject>consumer("backend", msg -> {
JsonObject json = msg.body();
switch (json.getString("op", "")) {
case "get": {
String productID = json.getString("id");
msg.reply(products.get(productID));
break;
}
case "add": {
String productID = json.getString("id");
JsonObject product = json.getJsonObject("product");
product.put("id", productID);
msg.reply(addProduct(product));
break;
}
case "list": {
JsonArray arr = new JsonArray();
products.forEach((k, v) -> arr.add(v));
msg.reply(arr);
break;
}
default: {
msg.fail(0, "operation not permitted");
}
}
});
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testEncodePrettily() throws Exception {
jsonArray.add("foo");
jsonArray.add(123);
jsonArray.add(1234l);
jsonArray.add(1.23f);
jsonArray.add(2.34d);
jsonArray.add(true);
byte[] bytes = TestUtils.randomByteArray(10);
jsonArray.add(bytes);
jsonArray.addNull();
jsonArray.add(new JsonObject().put("foo", "bar"));
jsonArray.add(new JsonArray().add("foo").add(123));
String strBytes = Base64.getEncoder().encodeToString(bytes);
String expected = "[ \"foo\", 123, 1234, 1.23, 2.34, true, \"" + strBytes + "\", null, {" + Utils.LINE_SEPARATOR +
" \"foo\" : \"bar\"" + Utils.LINE_SEPARATOR +
"}, [ \"foo\", 123 ] ]";
String json = jsonArray.encodePrettily();
assertEquals(expected, json);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testToString() {
jsonArray.add("foo").add(123);
assertEquals(jsonArray.encode(), jsonArray.toString());
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testMapRemoveIfPresentJsonArray() {
testMapRemoveIfPresent(new JsonArray().add("foo").add(2), new JsonArray().add("uihwqduh").add(false),
new JsonArray().add("qqddq").add(true));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testFromJsonArray() {
JsonArray object = new JsonArray();
object.add("the_string");
object.add(4);
object.add(true);
object.add("hello".getBytes());
object.add(new JsonObject().put("nested", 4));
object.add(new JsonArray().add(1).add(2).add(3));
List<Object> map = ConversionHelper.fromObject(object);
assertEquals(6, map.size());
assertEquals("the_string", map.get(0));
assertEquals(4, map.get(1));
assertEquals(true, map.get(2));
assertEquals("hello", new String(Base64.getDecoder().decode((String)map.get(3))));
assertEquals(Collections.singletonMap("nested", 4), map.get(4));
assertEquals(Arrays.asList(1, 2, 3), map.get(5));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testAddFloat() {
assertSame(jsonArray, jsonArray.add(123f));
assertEquals(Float.valueOf(123f), jsonArray.getFloat(0));
try {
jsonArray.add((Float)null);
fail();
} catch (NullPointerException e) {
// OK
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testMapReplaceJsonArray() {
testMapReplace(new JsonArray().add("foo").add(2), new JsonArray().add("uihwqduh").add(false),
new JsonArray().add("qqddq").add(true));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testEncodeToBuffer() throws Exception {
jsonArray.add("foo");
jsonArray.add(123);
jsonArray.add(1234l);
jsonArray.add(1.23f);
jsonArray.add(2.34d);
jsonArray.add(true);
byte[] bytes = TestUtils.randomByteArray(10);
jsonArray.add(bytes);
jsonArray.addNull();
jsonArray.add(new JsonObject().put("foo", "bar"));
jsonArray.add(new JsonArray().add("foo").add(123));
String strBytes = Base64.getEncoder().encodeToString(bytes);
Buffer expected = Buffer.buffer("[\"foo\",123,1234,1.23,2.34,true,\"" + strBytes + "\",null,{\"foo\":\"bar\"},[\"foo\",123]]", "UTF-8");
Buffer json = jsonArray.toBuffer();
assertArrayEquals(expected.getBytes(), json.getBytes());
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testAddInteger() {
assertSame(jsonArray, jsonArray.add(123));
assertEquals(Integer.valueOf(123), jsonArray.getInteger(0));
try {
jsonArray.add((Integer)null);
fail();
} catch (NullPointerException e) {
// OK
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testMapPutGetJsonArray() {
testMapPutGet(new JsonArray().add("foo").add(2), new JsonArray().add("uihwqduh").add(false));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCreateFromBuffer() {
JsonArray excepted = new JsonArray();
excepted.add("foobar");
excepted.add(123);
Buffer buf = Buffer.buffer(excepted.encode());
assertEquals(excepted, new JsonArray(buf));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testAddLong() {
assertSame(jsonArray, jsonArray.add(123l));
assertEquals(Long.valueOf(123l), jsonArray.getLong(0));
try {
jsonArray.add((Long)null);
fail();
} catch (NullPointerException e) {
// OK
}
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testMapRemoveJsonArray() {
testMapRemove(new JsonArray().add("foo").add(2), new JsonArray().add("uihwqduh").add(false));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testParseArrayValue() {
JsonParser parser = JsonParser.newParser();
AtomicInteger status = new AtomicInteger();
parser.arrayValueMode();
JsonArray expected = new JsonArray()
.add(3)
.add(3.5d)
.add(true)
.add(false)
.add("s")
.addNull()
.add(new JsonObject().put("foo", "bar"))
.add(new JsonArray().add(0).add(1).add(2))
.add(new byte[]{1, 2, 3});
parser.handler(event -> {
assertEquals(expected, event.value());
assertEquals(0, status.getAndIncrement());
});
parser.handle(expected.toBuffer());
assertEquals(1, status.get());
}
内容来源于网络,如有侵权,请联系作者删除!