/** * Return this JSON value in string representation, without quoting if this is a JSON string already. * * @return the string representation. */ default String formatAsString() { return isString() ? asString() : toString(); } }
/** * Return this JSON value in string representation, without quoting if this is a JSON string already. * * @return the string representation. */ default String formatAsString() { return isString() ? asString() : toString(); }
private static Map<String, String> getSpecificConfiguration(final JsonObject jsonObject) { return jsonObject.getValue(JsonFields.SPECIFIC_CONFIG) .filter(JsonValue::isObject) .map(JsonValue::asObject) .map(JsonObject::stream) .map(jsonFields -> jsonFields.collect(Collectors.toMap(JsonField::getKeyName, f -> f.getValue().isString() ? f.getValue().asString() : f.getValue().toString()))) .orElse(Collections.emptyMap()); }
private static Map<String, String> getSpecificConfiguration(final JsonObject jsonObject) { return jsonObject.getValue(JsonFields.SPECIFIC_CONFIG) .filter(JsonValue::isObject) .map(JsonValue::asObject) .map(JsonObject::stream) .map(jsonFields -> jsonFields.collect(Collectors.toMap(JsonField::getKeyName, f -> f.getValue().isString() ? f.getValue().asString() : f.getValue().toString()))) .orElse(Collections.emptyMap()); }
private boolean violatesThreshold(final JsonPointer key, final JsonValue value, final int overhead, final int threshold) { return null != value && value.isString() && !value.isNull() && threshold < value.asString().length() + totalOverhead(key, overhead); }
private boolean violatesThreshold(final JsonPointer key, final JsonValue value, final int overhead, final int threshold) { return null != value && value.isString() && !value.isNull() && threshold < value.asString().length() + totalOverhead(key, overhead); }
/** * Creates a new {@code HeaderMapping} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the HeaderMapping to be created. * @return a new HeaderMapping which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static HeaderMapping fromJson(final JsonObject jsonObject) { return new ImmutableHeaderMapping(jsonObject.stream() .filter(f -> f.getValue().isString()) .collect(Collectors.toMap(JsonField::getKeyName, jsonField -> jsonField.getValue().asString()))); }
/** * Creates a new {@code HeaderMapping} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the HeaderMapping to be created. * @return a new HeaderMapping which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static HeaderMapping fromJson(final JsonObject jsonObject) { return new ImmutableHeaderMapping(jsonObject.stream() .filter(f -> f.getValue().isString()) .collect(Collectors.toMap(JsonField::getKeyName, jsonField -> jsonField.getValue().asString()))); }
private void putJsonValue(final HeaderDefinition definition, final JsonValue jsonValue) { putCharSequence(definition, jsonValue.isString() ? jsonValue.asString() : jsonValue.toString()); }
@Override public S isString() { isNotNull(); assertThat(actual.isString()) .overridingErrorMessage("Expected JSON value <%s> to be a string but it was not.", actual) .isTrue(); return myself; }
protected static Map<String, String> toMap(final JsonValueContainer<JsonField> jsonObject) { checkNotNull(jsonObject, "JSON object"); final Map<String, String> result = new HashMap<>(jsonObject.getSize()); jsonObject.forEach(jsonField -> { final JsonValue jsonValue = jsonField.getValue(); final String stringValue = jsonValue.isString() ? jsonValue.asString() : jsonValue.toString(); result.put(jsonField.getKeyName(), stringValue); }); return result; }
@Override public S isNotString() { isNotNull(); assertThat(actual.isString()) .overridingErrorMessage("Expected JSON value <%s> not to be a string but it was.", actual) .isFalse(); return myself; }
protected static Map<String, String> toMap(final JsonValueContainer<JsonField> jsonObject) { checkNotNull(jsonObject, "JSON object"); final Map<String, String> result = new HashMap<>(jsonObject.getSize()); jsonObject.forEach(jsonField -> { final JsonValue jsonValue = jsonField.getValue(); final String stringValue = jsonValue.isString() ? jsonValue.asString() : jsonValue.toString(); result.put(jsonField.getKeyName(), stringValue); }); return result; }
private static boolean isJsonValueIllegal(final JsonValue entity) { final boolean result; if (entity.isArray()) { result = entity.asArray().stream().anyMatch(CommandWithOptionalEntityValidator::isJsonValueIllegal); } else if (entity.isObject()) { result = entity.asObject().stream().anyMatch(CommandWithOptionalEntityValidator::isJsonFieldIllegal); } else if (entity.isString()) { result = isStringIllegal(entity.asString()); } else { result = false; } return result; }
/** * Creates a new {@code MappingContext} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the MappingContext to be created. * @return a new MappingContext which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if {@code jsonObject} is not an appropriate JSON object. */ public static MappingContext fromJson(final JsonObject jsonObject) { final String mappingEngine = jsonObject.getValueOrThrow(JsonFields.MAPPING_ENGINE); final Map<String, String> options = jsonObject.getValueOrThrow(JsonFields.OPTIONS).stream() .collect(Collectors.toMap( e -> e.getKey().toString(), e -> e.getValue().isString() ? e.getValue().asString() : e.getValue().toString()) ); return of(mappingEngine, options); }
private static JsonObject createPolicyJsonObjectForPut(final String jsonString, final String policyId) { final JsonObject policyJsonObject = wrapJsonRuntimeException(() -> JsonFactory.newObject(jsonString)); policyJsonObject.getValue(Policy.JsonFields.ID.getPointer()) .ifPresent(policyIdJsonValue -> { if (!policyIdJsonValue.isString() || !policyId.equals(policyIdJsonValue.asString())) { throw PolicyIdNotExplicitlySettableException.newBuilder().build(); } }); return policyJsonObject.setValue(Policy.JsonFields.ID.getPointer(), JsonValue.of(policyId)); }
private void addInternalAttributes(final String path, final JsonValue jsonValue) { if (jsonValue == null || jsonValue.isNull()) { attributeInternally(path, null); } else if (jsonValue.isString()) { attributeInternally(path, jsonValue.asString()); } else if (jsonValue.isBoolean()) { attributeInternally(path, jsonValue.asBoolean()); } else if (jsonValue.isNumber()) { addNumberAttribute(path, jsonValue); } else if (jsonValue.isObject()) { jsonValue.asObject().getKeys().forEach(key -> // addInternalAttributes(path + PersistenceConstants.SLASH + key, jsonValue.asObject().getValue(key).orElse(null))); } }
private void addInternalAttributes(final String path, final JsonValue jsonValue) { if ((jsonValue == null) || jsonValue.isNull()) { attributeInternally(path, null); } else if (jsonValue.isString()) { attributeInternally(path, jsonValue.asString()); } else if (jsonValue.isBoolean()) { attributeInternally(path, jsonValue.asBoolean()); } else if (jsonValue.isNumber()) { addNumberAttribute(path, jsonValue); } else if (jsonValue.isObject()) { jsonValue.asObject().getKeys().forEach(key -> // addInternalAttributes(path + PersistenceConstants.SLASH + key, jsonValue.asObject().getValue(key).orElse(null))); } }
private void addInternalFeatures(final String path, final JsonValue jsonValue, final String featureId) { if ((jsonValue == null) || jsonValue.isNull()) { featureInternally(path, null, featureId); } else if (jsonValue.isString()) { featureInternally(path, jsonValue.asString(), featureId); } else if (jsonValue.isBoolean()) { featureInternally(path, jsonValue.asBoolean(), featureId); } else if (jsonValue.isNumber()) { addNumberFeature(path, jsonValue, featureId); } else if (jsonValue.isObject()) { jsonValue.asObject().getKeys().forEach(name -> // addInternalFeatures(path + "/" + name, jsonValue.asObject().getValue(name).orElse(null), featureId)); } }
private void addInternalFeatures(final String path, final JsonValue jsonValue, final String featureId) { if ((jsonValue == null) || jsonValue.isNull()) { featureInternally(path, null, featureId); } else if (jsonValue.isString()) { featureInternally(path, jsonValue.asString(), featureId); } else if (jsonValue.isBoolean()) { featureInternally(path, jsonValue.asBoolean(), featureId); } else if (jsonValue.isNumber()) { addNumberFeature(path, jsonValue, featureId); } else if (jsonValue.isObject()) { jsonValue.asObject().getKeys().forEach(name -> // addInternalFeatures(path + "/" + name, jsonValue.asObject().getValue(name).orElse(null), featureId)); } }