/** * Add an Object to the JSON array. * * @param value the value * @return a reference to this, so the API can be used fluently */ public JsonArray add(Object value) { Objects.requireNonNull(value); value = Json.checkAndCopy(value, false); list.add(value); return this; }
/** * Put an Object into the JSON object with the specified key. * * @param key the key * @param value the value * @return a reference to this, so the API can be used fluently */ public JsonObject put(String key, Object value) { Objects.requireNonNull(key); value = Json.checkAndCopy(value, false); map.put(key, value); return this; }
/** * Make a copy of the JSON array * * @return a copy */ @Override public JsonArray copy() { List<Object> copiedList = new ArrayList<>(list.size()); for (Object val: list) { val = Json.checkAndCopy(val, true); copiedList.add(val); } return new JsonArray(copiedList); }
/** * Copy the JSON object * * @return a copy of the object */ @Override public JsonObject copy() { Map<String, Object> copiedMap; if (map instanceof LinkedHashMap) { copiedMap = new LinkedHashMap<>(map.size()); } else { copiedMap = new HashMap<>(map.size()); } for (Map.Entry<String, Object> entry: map.entrySet()) { Object val = entry.getValue(); val = Json.checkAndCopy(val, true); copiedMap.put(entry.getKey(), val); } return new JsonObject(copiedMap); }
/** * Add an Object to the JSON array. * * @param value the value * @return a reference to this, so the API can be used fluently */ public JsonArray add(Object value) { Objects.requireNonNull(value); value = Json.checkAndCopy(value, false); list.add(value); return this; }
/** * Put an Object into the JSON object with the specified key. * * @param key the key * @param value the value * @return a reference to this, so the API can be used fluently */ public JsonObject put(String key, Object value) { Objects.requireNonNull(key); value = Json.checkAndCopy(value, false); map.put(key, value); return this; }
/** * Make a copy of the JSON array * * @return a copy */ @Override public JsonArray copy() { List<Object> copiedList = new ArrayList<>(list.size()); for (Object val: list) { val = Json.checkAndCopy(val, true); copiedList.add(val); } return new JsonArray(copiedList); }
/** * Copy the JSON object * * @return a copy of the object */ @Override public JsonObject copy() { Map<String, Object> copiedMap; if (map instanceof LinkedHashMap) { copiedMap = new LinkedHashMap<>(map.size()); } else { copiedMap = new HashMap<>(map.size()); } for (Map.Entry<String, Object> entry: map.entrySet()) { Object val = entry.getValue(); val = Json.checkAndCopy(val, true); copiedMap.put(entry.getKey(), val); } return new JsonObject(copiedMap); }