/** * Returns JSON key for the given character sequence. If the given key value is already a JSON key, this is * immediately properly cast and returned. * * @param keyValue the character sequence value of the JSON key to be created. * @return a new JSON key with {@code keyValue} as its value. * @throws NullPointerException if {@code keyValue} is {@code null}. * @throws IllegalArgumentException if {@code keyValue} is empty. */ static JsonKey of(final CharSequence keyValue) { return JsonFactory.newKey(keyValue); }
/** * Returns JSON key for the given character sequence. If the given key value is already a JSON key, this is * immediately properly cast and returned. * * @param keyValue the character sequence value of the JSON key to be created. * @return a new JSON key with {@code keyValue} as its value. * @throws NullPointerException if {@code keyValue} is {@code null}. * @throws IllegalArgumentException if {@code keyValue} is empty. */ static JsonKey of(final CharSequence keyValue) { return JsonFactory.newKey(keyValue); }
private static JsonKey reviseKeyName(final String jsonKeyName, final Function<String, String> jsonKeyNameReviser) { return JsonFactory.newKey(jsonKeyNameReviser.apply(jsonKeyName)); }
private static JsonKey reviseKeyName(final String jsonKeyName, final Function<String, String> jsonKeyNameReviser) { return JsonFactory.newKey(jsonKeyNameReviser.apply(jsonKeyName)); }
/** * Returns a new JSON field based on the specified key value pair. * * @param key the key of the field to be created. * @param value the value of the field to be created. {@code null} will be converted to the JSON NULL Literal. * @return a new JSON field containing the specified key value pair. * @throws NullPointerException if {@code key} is null. */ static JsonField newInstance(final CharSequence key, @Nullable final JsonValue value) { return JsonFactory.newField(JsonFactory.newKey(key), value); }
/** * Returns a new JSON field based on the specified key value pair. * * @param key the key of the field to be created. * @param value the value of the field to be created. {@code null} will be converted to the JSON NULL Literal. * @return a new JSON field containing the specified key value pair. * @throws NullPointerException if {@code key} is null. */ static JsonField newInstance(final CharSequence key, @Nullable final JsonValue value) { return JsonFactory.newField(JsonFactory.newKey(key), value); }
/** * Returns a new JSON field based on the specified key value pair and definition. * * @param key the key of the field to be created. * @param value the value of the field to be created. {@code null} will be converted to the JSON NULL Literal. * @param definition the definition of the field to be created. * @return a new JSON field containing the specified key value pair and definition. * @throws NullPointerException if {@code key} is {@code null}. */ static JsonField newInstance(final CharSequence key, @Nullable final JsonValue value, @Nullable final JsonFieldDefinition definition) { return JsonFactory.newField(JsonFactory.newKey(key), value, definition); }
/** * Returns this Permission constant as {@link JsonKey}. * * @return this Permission constant as known JSON key. */ public JsonKey toJsonKey() { return JsonFactory.newKey(name()); }
/** * Returns this Permission constant as {@link JsonKey}. * * @return this Permission constant as known JSON key. */ public JsonKey toJsonKey() { return JsonFactory.newKey(name()); }
/** * Returns a new JSON field based on the specified key value pair and definition. * * @param key the key of the field to be created. * @param value the value of the field to be created. {@code null} will be converted to the JSON NULL Literal. * @param definition the definition of the field to be created. * @return a new JSON field containing the specified key value pair and definition. * @throws NullPointerException if {@code key} is {@code null}. */ static JsonField newInstance(final CharSequence key, @Nullable final JsonValue value, @Nullable final JsonFieldDefinition definition) { return JsonFactory.newField(JsonFactory.newKey(key), value, definition); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> predicate) { final List<JsonField> fields = mapping.entrySet().stream().map(e -> JsonFactory.newField(JsonFactory.newKey(e.getKey()), JsonFactory.newValue(e.getValue()))).collect(Collectors.toList()); return JsonFactory.newObjectBuilder(fields).build(); }
@Override public JsonObject toJson(final JsonSchemaVersion schemaVersion, final Predicate<JsonField> predicate) { final List<JsonField> fields = mapping.entrySet().stream().map(e -> JsonFactory.newField(JsonFactory.newKey(e.getKey()), JsonFactory.newValue(e.getValue()))).collect(Collectors.toList()); return JsonFactory.newObjectBuilder(fields).build(); }
private JsonPointer getAbsolutePointer(final ResourceNode resourceNode) { final JsonPointer result = resourceNode.getParent() .filter(p -> PolicyTreeNode.Type.RESOURCE == p.getType()) .map(p -> (ResourceNode) p) .map(this::getAbsolutePointer) // Recursion! .orElseGet(JsonFactory::emptyPointer); return result.addLeaf(JsonFactory.newKey(resourceNode.getName())); }
private static Map<String, JsonField> toMap(final com.eclipsesource.json.JsonObject minimalJsonObject) { final Map<String, JsonField> result = new LinkedHashMap<>(minimalJsonObject.size()); for (final com.eclipsesource.json.JsonObject.Member member : minimalJsonObject) { final JsonKey key = newKey(member.getName()); final JsonValue value = convert(member.getValue()); result.put(key.toString(), newField(key, value)); } return result; }
/** * Converts the specified char sequence to a {@link JsonPointer} which is guaranteed to be not empty. * * @param keyOrPointer a string representation of a JSON pointer or a JsonKey. * @return the pointer. * @throws NullPointerException if {@code keyOrPointer} is {@code null}. * @throws IllegalArgumentException if {@code keyOrPointer} would lead to an empty JsonPointer. */ static JsonPointer getNonEmptyPointer(final CharSequence keyOrPointer) { requireNonNull(keyOrPointer, "The key or pointer char sequence must not be null!"); final JsonPointer result; if (isPointer(keyOrPointer)) { result = newPointer(keyOrPointer); } else { final JsonKey jsonKey = newKey(keyOrPointer); result = jsonKey.asPointer(); } if (result.isEmpty()) { throw new IllegalArgumentException("The key or pointer must not be empty!"); } return result; }
@Override public JsonObject toJson() { final JsonObjectBuilder jsonObjectBuilder = JsonFactory.newObjectBuilder(); jsonObjectBuilder.set(JSON_KEY_REACHABLE, reachable.stream().map(JsonValue::of).collect(JsonCollectors.valuesToArray())); jsonObjectBuilder.set(JSON_KEY_UNREACHABLE, unreachable.stream().map(JsonValue::of).collect(JsonCollectors.valuesToArray())); jsonObjectBuilder.set(JSON_KEY_SEEN_BY, seenBy.stream().map(JsonValue::of).collect(JsonCollectors.valuesToArray())); jsonObjectBuilder.set(JSON_KEY_LEADER, getLeader().orElse("<unknown>")); jsonObjectBuilder.set(JSON_KEY_OWN_ROLES, ownRoles.stream().map(JsonValue::of).collect(JsonCollectors.valuesToArray())); final JsonObjectBuilder rolesObjectBuilder = JsonFactory.newObjectBuilder(); roles.forEach(roleStatus -> { final JsonKey key = JsonFactory.newKey(roleStatus.getRole()); final JsonValue value = roleStatus.toJson(); final JsonFieldDefinition<JsonObject> fieldDefinition = JsonFactory.newJsonObjectFieldDefinition(key, FieldType.REGULAR); final JsonField field = JsonFactory.newField(key, value, fieldDefinition); rolesObjectBuilder.set(field); }); jsonObjectBuilder.set(JSON_KEY_ROLES, rolesObjectBuilder.build()); return jsonObjectBuilder.build(); }
public ThingQueryCommandResponseAssert withResourcePath(final CharSequence expectedResourcePath, final CharSequence... furtherResourcePathSegments) { final JsonKey[] subLevels; if (null != furtherResourcePathSegments) { subLevels = Stream.of(furtherResourcePathSegments) .map(JsonFactory::newKey) .toArray(JsonKey[]::new); } else { subLevels = new JsonKey[0]; } final JsonPointer expectedResourcePathPointer = JsonFactory.newPointer(JsonFactory.newKey(expectedResourcePath), subLevels); final JsonPointer actualResourcePath = actual.getResourcePath(); Assertions.assertThat((Object) actualResourcePath) .overridingErrorMessage("Expected ThingQueryCommandResponse to have resource path \n<%s> but it" + " had\n<%s>", expectedResourcePathPointer, actualResourcePath) .isEqualTo(expectedResourcePathPointer); return myself; }
public ThingModifyCommandResponseAssert withResourcePath(final CharSequence expectedResourcePath, final CharSequence... furtherResourcePathSegments) { final JsonKey[] subLevels; if (null != furtherResourcePathSegments) { subLevels = Stream.of(furtherResourcePathSegments) .map(JsonFactory::newKey) .toArray(JsonKey[]::new); } else { subLevels = new JsonKey[0]; } final JsonPointer expectedResourcePathPointer = JsonFactory.newPointer(JsonFactory.newKey(expectedResourcePath), subLevels); final JsonPointer actualResourcePath = actual.getResourcePath(); Assertions.assertThat((Object) actualResourcePath) .overridingErrorMessage("Expected ThingModifyCommandResponse to have resource path \n<%s> but it" + " had\n<%s>", expectedResourcePathPointer, actualResourcePath) .isEqualTo(expectedResourcePathPointer); return myself; }
@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(JSON_SCHEMA_VERSION, schemaVersion.toInt(), predicate); features.values() .forEach(feature -> { final JsonKey key = JsonFactory.newKey(feature.getId()); final JsonValue value = feature.toJson(schemaVersion, thePredicate); final JsonFieldDefinition<JsonObject> fieldDefinition = JsonFactory.newJsonObjectFieldDefinition(key, FieldType.REGULAR, JsonSchemaVersion.V_1, JsonSchemaVersion.V_2); final JsonField field = JsonFactory.newField(key, value, fieldDefinition); jsonObjectBuilder.set(field, predicate); }); return jsonObjectBuilder.build(); }
@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(JSON_SCHEMA_VERSION, schemaVersion.toInt(), predicate); features.values() .forEach(feature -> { final JsonKey key = JsonFactory.newKey(feature.getId()); final JsonValue value = feature.toJson(schemaVersion, thePredicate); final JsonFieldDefinition<JsonObject> fieldDefinition = JsonFactory.newJsonObjectFieldDefinition(key, FieldType.REGULAR, JsonSchemaVersion.V_1, JsonSchemaVersion.V_2); final JsonField field = JsonFactory.newField(key, value, fieldDefinition); jsonObjectBuilder.set(field, predicate); }); return jsonObjectBuilder.build(); }