@Override public JsonObject transform(JsonObject jsonObject) { return jsonObject.copy(); }
public JsonObject toJson() { return json != null ? json.copy() : new JsonObject(); }
/** * Create an instance from a {@link io.vertx.core.json.JsonObject} * * @param json the JsonObject to create it from */ public MetricsOptions(JsonObject json) { this(); MetricsOptionsConverter.fromJson(json, this); this.json = json.copy(); }
@Override public void process(JsonObject document, Handler<AsyncResult<JsonObject>> resultHandler) { System.out.println("Processing..."); JsonObject result = document.copy(); if (!document.containsKey("name")) { resultHandler.handle(ServiceException.fail(NO_NAME_ERROR, "No name in the document")); } else if (document.getString("name").isEmpty() || document.getString("name").equalsIgnoreCase("bad")) { resultHandler.handle(ServiceException.fail(BAD_NAME_ERROR, "Bad name in the document: " + document.getString("name"), new JsonObject().put("name", document.getString("name")))); } else { result.put("approved", true); resultHandler.handle(Future.succeededFuture(result)); } }
case "config": if (member.getValue() instanceof JsonObject) { obj.setConfig(((JsonObject)member.getValue()).copy());
@Test public void testInvalidValsOnCopy3() { Map<String, Object> invalid = new HashMap<>(); List<Object> invalid2 = new ArrayList<>(); invalid2.add(new SomeClass()); invalid.put("bar",invalid2); JsonObject object = new JsonObject(invalid); try { object.copy(); fail(); } catch (IllegalStateException e) { // OK } }
@Test public void testInvalidValsOnCopy2() { Map<String, Object> invalid = new HashMap<>(); Map<String, Object> invalid2 = new HashMap<>(); invalid2.put("foo", new SomeClass()); invalid.put("bar",invalid2); JsonObject object = new JsonObject(invalid); try { object.copy(); fail(); } catch (IllegalStateException e) { // OK } }
@Test public void testInvalidValsOnCopy1() { Map<String, Object> invalid = new HashMap<>(); invalid.put("foo", new SomeClass()); JsonObject object = new JsonObject(invalid); try { object.copy(); fail(); } catch (IllegalStateException e) { // OK } }
@Test public void testOrder() { List<String> expectedKeys = new ArrayList<>(); int size = 100; StringBuilder sb = new StringBuilder("{"); for (int i = 0;i < size;i++) { sb.append("\"key-").append(i).append("\":").append(i).append(","); expectedKeys.add("key-" + i); } sb.setCharAt(sb.length() - 1, '}'); JsonObject obj = new JsonObject(sb.toString()); List<String> keys = new ArrayList<>(); // ordered because of Jackson uses a LinkedHashMap obj.forEach(e -> keys.add(e.getKey())); assertEquals(expectedKeys, keys); keys.clear(); // Ordered because we preserve the LinkedHashMap obj.copy().forEach(e -> keys.add(e.getKey())); assertEquals(expectedKeys, keys); }
@Test public void testStreamCorrectTypes() throws Exception { String json = "{\"object1\": [{\"object2\": 12}]}"; JsonObject object = new JsonObject(json); testStreamCorrectTypes(object.copy()); testStreamCorrectTypes(object); }
@Test public void testStreamCorrectTypes() throws Exception { String json = "{\"object1\": {\"object2\": 12}}"; JsonObject object = new JsonObject(json); testStreamCorrectTypes(object.copy()); testStreamCorrectTypes(object); }
/** * Copy constructor * * @param other the instance to copy */ public DeploymentOptions(DeploymentOptions other) { this.config = other.getConfig() == null ? null : other.getConfig().copy(); this.worker = other.isWorker(); this.isolationGroup = other.getIsolationGroup(); this.ha = other.isHa(); this.extraClasspath = other.getExtraClasspath() == null ? null : new ArrayList<>(other.getExtraClasspath()); this.instances = other.instances; this.isolatedClasses = other.getIsolatedClasses() == null ? null : new ArrayList<>(other.getIsolatedClasses()); this.workerPoolName = other.workerPoolName; setWorkerPoolSize(other.workerPoolSize); setMaxWorkerExecuteTime(other.maxWorkerExecuteTime); this.maxWorkerExecuteTimeUnit = other.maxWorkerExecuteTimeUnit; }
Handler<AsyncResult<String>> completionHandler, ClassLoader tccl, Verticle... verticles) { JsonObject conf = options.getConfig() == null ? new JsonObject() : options.getConfig().copy(); // Copy it String poolName = options.getWorkerPoolName();
@Test public void testCopy() { jsonObject.put("foo", "bar"); jsonObject.put("quux", 123); JsonObject obj = createJsonObject(); jsonObject.put("wibble", obj); jsonObject.put("eek", new StringBuilder("blah")); // CharSequence JsonObject copy = jsonObject.copy(); assertNotSame(jsonObject, copy); assertEquals(jsonObject, copy); copy.put("blah", "flib"); assertFalse(jsonObject.containsKey("blah")); copy.remove("foo"); assertFalse(copy.containsKey("foo")); assertTrue(jsonObject.containsKey("foo")); jsonObject.put("oob", "flarb"); assertFalse(copy.containsKey("oob")); jsonObject.remove("quux"); assertFalse(jsonObject.containsKey("quux")); assertTrue(copy.containsKey("quux")); JsonObject nested = jsonObject.getJsonObject("wibble"); JsonObject nestedCopied = copy.getJsonObject("wibble"); assertNotSame(nested, nestedCopied); assertEquals(nested, nestedCopied); assertEquals("blah", copy.getString("eek")); }
@Test public void testInvalidValsOnCopy1() { Map<String, Object> invalid = new HashMap<>(); invalid.put("foo", new SomeClass()); JsonObject object = new JsonObject(invalid); try { object.copy(); fail(); } catch (IllegalStateException e) { // OK } }
@Test public void testStreamCorrectTypes() throws Exception { String json = "{\"object1\": {\"object2\": 12}}"; JsonObject object = new JsonObject(json); testStreamCorrectTypes(object.copy()); testStreamCorrectTypes(object); }
@Test public void testStreamCorrectTypes() throws Exception { String json = "{\"object1\": [{\"object2\": 12}]}"; JsonObject object = new JsonObject(json); testStreamCorrectTypes(object.copy()); testStreamCorrectTypes(object); }
@Test public void testRegisterPermittedStructureMatch() throws Exception { JsonObject match = new JsonObject().put("fib", "wib").put("oop", 12); sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setMatch(match))); testReceive(addr, match); JsonObject json1 = match.copy(); json1.put("blah", "foob"); testReceive(addr, json1); JsonObject json2 = json1.copy(); json2.remove("fib"); testReceiveFail(addr, json2); }
@Test public void testRegisterPermittedStructureMatchWithAddress() throws Exception { JsonObject match = new JsonObject().put("fib", "wib").put("oop", 12); sockJSHandler.bridge(defaultOptions.addOutboundPermitted(new PermittedOptions().setMatch(match).setAddress(addr))); testReceive(addr, match); JsonObject json1 = match.copy(); json1.put("blah", "foob"); testReceive(addr, json1); JsonObject json2 = json1.copy(); json2.remove("fib"); testReceiveFail(addr, json2); }