Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions vertx-core/src/main/java/io/vertx/core/json/JsonObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,20 @@ public static JsonObject of(String k1, Object v1, String k2, Object v2, String k
return obj;
}

/**
* Create a JsonObject from the given map entries.
* @param entries All the map entries to add the JSON object.
* @return a JsonObject containing the specified mappings.
*/
@SafeVarargs
public static JsonObject of(Map.Entry<String, Object>... entries) {
JsonObject obj = new JsonObject(new LinkedHashMap<>(entries.length));
for (Map.Entry<String, Object> entry : entries) {
obj.put(entry.getKey(), entry.getValue());
}
return obj;
}

/**
* Create a JsonObject from the fields of a Java object.
* Faster than calling `new JsonObject(Json.encode(obj))`.
Expand Down
16 changes: 16 additions & 0 deletions vertx-core/src/test/java/io/vertx/tests/json/JsonObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ public void setUp() throws Exception {
jsonObject = new JsonObject();
}

// @Test
// public void testJsonObjectOfMapEntryArgs() {
// Map.Entry<String, Object> e1 = Map.entry("key1", "value1");
// Map.Entry<String, Object> e2 = Map.entry("key2", "value2");
// Map.Entry<String, Object> e3 = Map.entry("key3", "value3");
// Map.Entry<String, Object> e4 = Map.entry("key4", "value4");
// Map.Entry<String, Object> e5 = Map.entry("key5", "value5");
// JsonObject jobj = JsonObject.of(e1, e2, e3, e4, e5);
//
// assertEquals("value1", jobj.getString("key1"));
// assertEquals("value2", jobj.getString("key2"));
// assertEquals("value3", jobj.getString("key3"));
// assertEquals("value4", jobj.getString("key4"));
// assertEquals("value5", jobj.getString("key5"));
// }

@Test
public void testGetInteger() {
jsonObject.put("foo", 123);
Expand Down
Loading