@Override public void endObjectValue(final List<JsonField> jsonFields, final String name) { final JsonField jsonField = JsonField.newInstance(name, jsonValue); jsonFields.add(jsonField); final StringBuilder stringBuilder = stringBuilders.peek(); if (null != stringBuilder) { stringBuilder.append(getEscapedJsonString(name)); stringBuilder.append(':'); stringBuilder.append(valueString); stringBuilder.append(DELIMITER); } }
private static JsonObject toJsonObject(final Map<?, ?> map) { return map.entrySet().stream() .map(entry -> JsonField.newInstance(String.valueOf(entry.getKey()), toJson(entry.getValue()))) .collect(JsonCollectors.fieldsToObject()); }
private static JsonObject toJsonObject(final Map<?, ?> map) { return map.entrySet().stream() .map(entry -> JsonField.newInstance(String.valueOf(entry.getKey()), toJson(entry.getValue()))) .collect(JsonCollectors.fieldsToObject()); }
@Override public void endObjectValue(final List<JsonField> jsonFields, final String name) { final List<JsonField> jsonObjectBuilder = jsonObjectBuilders.peek(); if (null != jsonObjectBuilder) { defaultHandler.endObjectValue(jsonObjectBuilder, name); } else { jsonFields.add(JsonField.newInstance(name, defaultHandler.getValue())); } }
@Override public <T> JsonObject set(final JsonFieldDefinition<T> fieldDefinition, @Nullable final T value) { requireNonNull(fieldDefinition, "The JSON field definition to set the value for must not be null!"); final JsonPointer pointer = fieldDefinition.getPointer(); final JsonKey leafKey = pointer.getLeaf().orElseThrow(() -> { final String msgTemplate = "The pointer of the field definition <{0}> must not be empty!"; return new IllegalArgumentException(MessageFormat.format(msgTemplate, fieldDefinition)); }); final JsonField field = JsonField.newInstance(leafKey, JsonValue.of(value), fieldDefinition); return setFieldInHierarchy(this, pointer, field); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); jsonObjectBuilder.set(JsonFields.MAPPING_ENGINE, mappingEngine, predicate); jsonObjectBuilder.set(JsonFields.OPTIONS, options.entrySet().stream() .map(e -> JsonField.newInstance(e.getKey(), JsonValue.of(e.getValue()))) .collect(JsonCollectors.fieldsToObject()), predicate); return jsonObjectBuilder.build(); }
@Override public JsonObject setValue(final CharSequence key, final JsonValue value) { final JsonPointer pointer = JsonFactory.getNonEmptyPointer(key); final JsonKey leafKey = pointer.getLeaf().orElse(ROOT_KEY); final Optional<JsonFieldDefinition> keyDefinition = getDefinitionForKey(leafKey); return setFieldInHierarchy(this, pointer, JsonField.newInstance(leafKey, value, keyDefinition.orElse(null))); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> thePredicate) { final Predicate<JsonField> predicate = schemaVersion.and(thePredicate); final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); jsonObjectBuilder.set(JsonFields.MAPPING_ENGINE, mappingEngine, predicate); jsonObjectBuilder.set(JsonFields.OPTIONS, options.entrySet().stream() .map(e -> JsonField.newInstance(e.getKey(), JsonValue.of(e.getValue()))) .collect(JsonCollectors.fieldsToObject()), predicate); return jsonObjectBuilder.build(); }
private JsonObject removeForPointer(final JsonPointer pointer) { final JsonObject result; final JsonKey rootKey = pointer.getRoot().orElse(ROOT_KEY); final Optional<JsonFieldDefinition> rootKeyDefinition = getDefinitionForKey(rootKey); if (pointer.isEmpty()) { result = this; } else if (1 == pointer.getLevelCount()) { result = removeValueForKey(rootKey); } else { final JsonPointer nextPointerLevel = pointer.nextLevel(); final Predicate<JsonObject> containsNextLevelRootKey = jsonObject -> nextPointerLevel.getRoot() .map(jsonObject::contains) .orElse(false); result = getValueForKey(rootKey) .filter(JsonValue::isObject) .map(JsonValue::asObject) .filter(containsNextLevelRootKey) .map(jsonObject -> jsonObject.remove(nextPointerLevel)) // Recursion .map(withoutValue -> JsonField.newInstance(rootKey, withoutValue, rootKeyDefinition.orElse(null))) .map(this::set) .orElse(this); } return result; }
if (1 >= pointer.getLevelCount()) { result = rootKeyValue.map( jsonValue -> JsonField.newInstance(rootKey, jsonValue, rootKeyDefinition.orElse(null))) .map(jsonField -> Collections.singletonMap(jsonField.getKeyName(), jsonField)) .map(ImmutableJsonObject::of) .map(jsonValue -> JsonField.newInstance(rootKey, jsonValue, rootKeyDefinition.orElse(null))) .map(jsonField -> Collections.singletonMap(jsonField.getKeyName(), jsonField)) .map(ImmutableJsonObject::of)
.map(entry -> JsonField.newInstance(entry.getKey(), JsonValue.of(entry.getValue()))) .collect(JsonCollectors.fieldsToObject());
jsonObjectBuilder.set(JsonFields.SPECIFIC_CONFIG, specificConfig.entrySet() .stream() .map(entry -> JsonField.newInstance(entry.getKey(), JsonValue.of(entry.getValue()))) .collect(JsonCollectors.fieldsToObject()), predicate);
.map(entry -> JsonField.newInstance(entry.getKey(), JsonValue.of(entry.getValue()))) .collect(JsonCollectors.fieldsToObject());
jsonObjectBuilder.set(JsonFields.SPECIFIC_CONFIG, specificConfig.entrySet() .stream() .map(entry -> JsonField.newInstance(entry.getKey(), JsonValue.of(entry.getValue()))) .collect(JsonCollectors.fieldsToObject()), predicate);