/** * Returns a new mutable builder for a {@code JsonObject}. * * @return a new JSON object builder. */ public static JsonObjectBuilder newObjectBuilder() { return ImmutableJsonObjectBuilder.newInstance(); }
/** * Returns a new mutable builder for a {@code JsonObject}. * * @return a new JSON object builder. */ public static JsonObjectBuilder newObjectBuilder() { return ImmutableJsonObjectBuilder.newInstance(); }
/** * Returns a new mutable builder for the specified {@code JsonField}s. The returned builder is already initialised * with the data of the provided JSON object. This method is useful if an existing JSON object should be strongly * modified but the amount of creating objects should be kept low at the same time. * * @param jsonFields are the initial data of the returned builder. * @return a new JSON object builder with pre-filled data of {@code jsonFields}. * @throws NullPointerException if {@code jsonFields} is {@code null}. */ public static JsonObjectBuilder newObjectBuilder(final Iterable<JsonField> jsonFields) { requireNonNull(jsonFields, "The initial JSON fields must not be null!"); final JsonObjectBuilder result = ImmutableJsonObjectBuilder.newInstance(); result.setAll(jsonFields); return result; }
private static JsonObjectBuilder setFieldInHierarchy(final ImmutableJsonObjectBuilder target, final JsonPointer pointer, final JsonField field) { if (1 >= pointer.getLevelCount()) { return target.set(field); } final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY); final ImmutableJsonObjectBuilder newTarget = newInstance(); final JsonField rootJsonField = target.fields.get(rootKey.toString()); if (null != rootJsonField) { final JsonValue rootValue = rootJsonField.getValue(); if (rootValue.isObject() && !rootValue.isNull()) { newTarget.setAll(rootValue.asObject()); } } // let the recursion begin >:-( final JsonObject jsonObject = setFieldInHierarchy(newTarget, pointer.nextLevel(), field).build(); return target.set(rootKey, jsonObject); }
private static JsonObjectBuilder setFieldInHierarchy(final ImmutableJsonObjectBuilder target, final JsonPointer pointer, final JsonField field) { if (1 >= pointer.getLevelCount()) { return target.set(field); } final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY); final ImmutableJsonObjectBuilder newTarget = newInstance(); final JsonField rootJsonField = target.fields.get(rootKey.toString()); if (null != rootJsonField) { final JsonValue rootValue = rootJsonField.getValue(); if (rootValue.isObject() && !rootValue.isNull()) { newTarget.setAll(rootValue.asObject()); } } // let the recursion begin >:-( final JsonObject jsonObject = setFieldInHierarchy(newTarget, pointer.nextLevel(), field).build(); return target.set(rootKey, jsonObject); }