private JsonArray lazyLoadThingsJsonArray() { if (things == null) { things = JsonFactory.readFrom(thingsPlainJson).asArray(); } return things; }
private JsonArray lazyLoadThingsJsonArray() { if (things == null) { things = JsonFactory.readFrom(thingsPlainJson).asArray(); } return things; }
private JsonArray lazyLoadThingsJsonArray() { if (things == null) { things = JsonFactory.readFrom(thingsPlainJson).asArray(); } return things; }
private JsonArray lazyLoadThingsJsonArray() { if (things == null) { things = JsonFactory.readFrom(thingsPlainJson).asArray(); } return things; }
private Set<String> tryToCreateSetFrom(final JsonValue json) { try { return json.asArray().stream() .filter(JsonValue::isString) .map(JsonValue::asString) .collect(Collectors.toSet()); } catch (final UnsupportedOperationException | JsonParseException e) { if (system != null) { system.log().error(e, "Could not deserialize JSON: '{}'", json); } else { System.err.println("Could not deserialize JSON: '" + json + "': " + e.getMessage()); } return null; } }
private Set<String> tryToCreateSetFrom(final JsonValue json) { try { return json.asArray().stream() .filter(JsonValue::isString) .map(JsonValue::asString) .collect(Collectors.toSet()); } catch (final UnsupportedOperationException | JsonParseException e) { if (system != null) { system.log().error(e, "Could not deserialize JSON: '{}'", json); } else { System.err.println("Could not deserialize JSON: '" + json + "': " + e.getMessage()); } return null; } }
@Override public RetrieveLoggerConfigResponse setEntity(final JsonValue entity) { return of(getServiceName().orElse(null), getInstance().orElse(null), entity.asArray().stream() .filter(JsonValue::isObject) .map(JsonValue::asObject) .map(ImmutableLoggerConfig::fromJson) .collect(Collectors.toList()), getDittoHeaders()); }
@Override public RetrieveLoggerConfigResponse setEntity(final JsonValue entity) { return of(getServiceName().orElse(null), getInstance().orElse(null), entity.asArray().stream() .filter(JsonValue::isObject) .map(JsonValue::asObject) .map(ImmutableLoggerConfig::fromJson) .collect(Collectors.toList()), getDittoHeaders()); }
@Override public RetrieveFeatureDefinitionResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(thingId, featureId, entity.asArray(), getDittoHeaders()); }
private static JsonValue mergeJsonValues(final JsonValue value1, final JsonValue value2) { final JsonValue result; if (areJsonObjects(value1, value2)) { result = mergeJsonObjects(value1.asObject(), value2.asObject()); } else if (areJsonArrays(value1, value2)) { result = mergeJsonArrays(value1.asArray(), value2.asArray()); } else { result = value1; } return result; }
@Override public RetrieveFeatureDefinitionResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(thingId, featureId, entity.asArray(), getDittoHeaders()); }
@Override public SudoRetrieveThingsResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(entity.asArray(), getDittoHeaders()); }
@Override public RetrieveThingsResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(entity.asArray(), namespace, getDittoHeaders()); }
@Override public SudoRetrieveThingsResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(entity.asArray(), getDittoHeaders()); }
@Override public RetrieveThingsResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); return of(entity.asArray(), namespace, getDittoHeaders()); }
/** * Creates a new JSON array from the given string. * * @param jsonString the string that represents the JSON array. * @return the JSON array that has been created from the string. * @throws NullPointerException if {@code jsonString} is {@code null}. * @throws IllegalArgumentException if {@code jsonString} is empty. * @throws JsonParseException if {@code jsonString} does not contain a valid JSON array. */ public static JsonArray newArray(final String jsonString) { requireNonNull(jsonString, "The JSON string to create JSON array from must not be null!"); if (jsonString.isEmpty()) { throw new IllegalArgumentException("The JSON string to create a JSON array from must not be empty!"); } if (isJsonNullLiteralString(jsonString)) { return nullArray(); } else { final JsonValue jsonValue = JsonValueParser.fromString().apply(jsonString); if (!jsonValue.isArray()) { final String msgPattern = "<{0}> is not a valid JSON array!"; throw JsonParseException.newBuilder().message(MessageFormat.format(msgPattern, jsonString)).build(); } return jsonValue.asArray(); } }
@Nullable private JsonValue getViewForJsonValueOrNull(final JsonValue jsonValue, final Set<String> subjectIds, final Permissions permissions) { final JsonValue result; if (jsonValue.isObject()) { result = getViewForJsonObjectOrNull(jsonValue.asObject(), subjectIds, permissions); } else if (jsonValue.isArray()) { result = getViewForJsonArrayOrNull(jsonValue.asArray(), subjectIds, permissions); } else if (grantRevokeIndex.hasPermissions(subjectIds, permissions)) { result = jsonValue; } else { result = null; } 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; }
private static void compareValuesWithFieldKey(final JsonKey key, final JsonValue expectedFieldValue, final JsonValue actualFieldValue, final boolean compareFieldDefinitions) { if (expectedFieldValue.isObject() && actualFieldValue.isObject() && !compareFieldDefinitions) { DittoJsonAssertions.assertThat(actualFieldValue.asObject()) .isEqualToIgnoringFieldDefinitions(expectedFieldValue.asObject()); } else if (areArraysOfEqualSize(expectedFieldValue, actualFieldValue) && !compareFieldDefinitions) { final JsonArray expectedArray = expectedFieldValue.asArray(); final JsonArray actualArray = actualFieldValue.asArray(); IntStream.range(0, expectedArray.getSize()) .forEach(i -> expectedArray.get(i).ifPresent(expectedElement -> actualArray.get(i).ifPresent(actualElement -> compareValuesWithFieldKey(key, expectedElement, actualElement, false)))); } else { Assertions.assertThat(actualFieldValue) .as("Values of JsonField <%s> are equal", key) .isEqualTo(expectedFieldValue); } }