本文整理了Java中io.vertx.core.json.JsonArray.<init>()
方法的一些代码示例,展示了JsonArray.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonArray.<init>()
方法的具体详情如下:
包路径:io.vertx.core.json.JsonArray
类名称:JsonArray
方法名:<init>
[英]Create an empty instance
[中]创建一个空实例
代码示例来源:origin: eclipse-vertx/vert.x
@Override
public Object next() {
Object val = listIter.next();
if (val instanceof Map) {
val = new JsonObject((Map)val);
} else if (val instanceof List) {
val = new JsonArray((List)val);
}
return val;
}
代码示例来源:origin: eclipse-vertx/vert.x
public HAManager(VertxInternal vertx, DeploymentManager deploymentManager, ClusterManager clusterManager,
Map<String, String> clusterMap, int quorumSize, String group, boolean enabled) {
this.vertx = vertx;
this.deploymentManager = deploymentManager;
this.clusterManager = clusterManager;
this.clusterMap = clusterMap;
this.quorumSize = enabled ? quorumSize : 0;
this.group = enabled ? group : "__DISABLED__";
this.enabled = enabled;
this.haInfo = new JsonObject().put("verticles", new JsonArray()).put("group", this.group);
this.nodeID = clusterManager.getNodeID();
}
代码示例来源: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 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 testCommentsInJson() {
String jsonWithComments =
"// single line comment\n" +
"/*\n" +
" This is a multi \n" +
" line comment\n" +
"*/\n" +
"[\n" +
"// another single line comment this time inside the JSON array itself\n" +
" \"foo\", \"bar\" // and a single line comment at end of line \n" +
"/*\n" +
" This is a another multi \n" +
" line comment this time inside the JSON array itself\n" +
"*/\n" +
"]";
JsonArray json = new JsonArray(jsonWithComments);
assertEquals("[\"foo\",\"bar\"]", json.encode());
}
代码示例来源: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 testInvalidJson() {
String invalid = "qiwjdoiqwjdiqwjd";
try {
new JsonArray(invalid);
fail();
} catch (DecodeException e) {
// OK
}
}
代码示例来源: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 testJsonArrayEquality() {
JsonObject obj = new JsonObject(Collections.singletonMap("abc", Collections.singletonList(3)));
assertEquals(obj, new JsonObject(Collections.singletonMap("abc", Collections.singletonList(3))));
assertEquals(obj, new JsonObject(Collections.singletonMap("abc", Collections.singletonList(3L))));
assertEquals(obj, new JsonObject(Collections.singletonMap("abc", new JsonArray().add(3))));
assertEquals(obj, new JsonObject(Collections.singletonMap("abc", new JsonArray().add(3L))));
assertNotEquals(obj, new JsonObject(Collections.singletonMap("abc", Collections.singletonList(4))));
assertNotEquals(obj, new JsonObject(Collections.singletonMap("abc", new JsonArray().add(4))));
JsonArray array = new JsonArray(Collections.singletonList(Collections.singletonList(3)));
assertEquals(array, new JsonArray(Collections.singletonList(Collections.singletonList(3))));
assertEquals(array, new JsonArray(Collections.singletonList(Collections.singletonList(3L))));
assertEquals(array, new JsonArray(Collections.singletonList(new JsonArray().add(3))));
assertEquals(array, new JsonArray(Collections.singletonList(new JsonArray().add(3L))));
assertNotEquals(array, new JsonArray(Collections.singletonList(Collections.singletonList(4))));
assertNotEquals(array, new JsonArray(Collections.singletonList(new JsonArray().add(4))));
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCreateFromList() {
List<Object> list = new ArrayList<>();
list.add("foo");
list.add(123);
JsonArray arr = new JsonArray(list);
assertEquals("foo", arr.getString(0));
assertEquals(Integer.valueOf(123), arr.getInteger(1));
assertSame(list, arr.getList());
}
代码示例来源: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
@Test
public void testInvalidValsOnCopy2() {
List<Object> invalid = new ArrayList<>();
List<Object> invalid2 = new ArrayList<>();
invalid2.add(new SomeClass());
invalid.add(invalid2);
JsonArray arr = new JsonArray(invalid);
try {
arr.copy();
fail();
} catch (IllegalStateException e) {
// OK
}
}
代码示例来源:origin: eclipse-vertx/vert.x
/**
* Get the Object value at position {@code pos} in the array.
*
* @param pos the position in the array
* @return the Integer, or null if a null value present
*/
public Object getValue(int pos) {
Object val = list.get(pos);
if (val instanceof Map) {
val = new JsonObject((Map)val);
} else if (val instanceof List) {
val = new JsonArray((List)val);
}
return val;
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testJsonObjectEquality2() {
JsonObject obj1 = new JsonObject().put("arr", new JsonArray().add("x"));
List < Object > list = new ArrayList<>();
list.add("x");
Map<String, Object> map = new HashMap<>();
map.put("arr", list);
JsonObject obj2 = new JsonObject(map);
Iterator<Map.Entry<String, Object>> iter = obj2.iterator();
// There was a bug where iteration of entries caused the underlying object to change resulting in a
// subsequent equals changing
while (iter.hasNext()) {
Map.Entry<String, Object> entry = iter.next();
}
assertEquals(obj2, obj1);
}
代码示例来源:origin: eclipse-vertx/vert.x
@Test
public void testCreateFromListCharSequence() {
List<Object> list = new ArrayList<>();
list.add("foo");
list.add(123);
list.add(new StringBuilder("eek"));
JsonArray arr = new JsonArray(list);
assertEquals("foo", arr.getString(0));
assertEquals(Integer.valueOf(123), arr.getInteger(1));
assertEquals("eek", arr.getString(2));
assertSame(list, arr.getList());
}
代码示例来源: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 testInvalidValsOnCopy3() {
List<Object> invalid = new ArrayList<>();
Map<String, Object> invalid2 = new HashMap<>();
invalid2.put("foo", new SomeClass());
invalid.add(invalid2);
JsonArray arr = new JsonArray(invalid);
try {
arr.copy();
fail();
} catch (IllegalStateException e) {
// OK
}
}
代码示例来源:origin: eclipse-vertx/vert.x
/**
* Remove the value at the specified position in the JSON array.
*
* @param pos the position to remove the value at
* @return the removed value if removed, null otherwise. If the value is a Map, a {@link JsonObject} is built from
* this Map and returned. It the value is a List, a {@link JsonArray} is built form this List and returned.
*/
public Object remove(int pos) {
Object removed = list.remove(pos);
if (removed instanceof Map) {
return new JsonObject((Map) removed);
} else if (removed instanceof ArrayList) {
return new JsonArray((List) removed);
}
return removed;
}
代码示例来源: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));
}
内容来源于网络,如有侵权,请联系作者删除!