@Override public ImmutableJsonArray add(final int value, final int... furtherValues) { checkFurtherValues(furtherValues); return add(JsonValue.of(value), Arrays.stream(furtherValues) .mapToObj(JsonValue::of) .toArray(JsonValue[]::new)); }
private JsonValue fixViolation(final JsonPointer key, final JsonValue value, final int overhead, final int threshold) { final int cutAt = Math.max(0, threshold - totalOverhead(key, overhead)); return JsonValue.of(value.asString().substring(0, cutAt)); }
private static StatusInfo mapToStatusInfo(final Status status, final @Nullable String message) { final List<StatusDetailMessage> details; if (message == null) { details = Collections.emptyList(); } else { final StatusDetailMessage.Level level = mapToMessageLevel(status); final StatusDetailMessage detailMessage = StatusDetailMessage.of(level, JsonValue.of(message)); details = Collections.singletonList(detailMessage); } return of(status, details, Collections.emptyList(), null); }
@Override public ImmutableJsonArray add(final String value, final String... furtherValues) { checkValue(value); checkFurtherValues(furtherValues); return add(JsonValue.of(value), Arrays.stream(furtherValues) .map(JsonValue::of) .toArray(JsonValue[]::new)); }
@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); }
/** * Sets the given attribute on a copy of this Thing. * * @param attributePath the hierarchical path to the attribute value. * @param attributeValue the attribute value to be set. * @return a copy of this Thing with the given attribute. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code attributePath} is empty. */ default Thing setAttribute(final CharSequence attributePath, final int attributeValue) { return setAttribute(JsonPointer.of(attributePath), JsonValue.of(attributeValue)); }
/** * Sets the value of a property which is referred by the given JSON Pointer. * * @param pointer defines the hierarchical path to the property value to be set. * @param propertyValue the property value to be set. * @return a copy of this Feature with the given property value set. * @throws NullPointerException if any argument is {@code null}. */ default Feature setProperty(final CharSequence pointer, final int propertyValue) { return setProperty(JsonPointer.of(pointer), JsonValue.of(propertyValue)); }
/** * Sets the value of a property which is referred by the given JSON Pointer. * * @param pointer defines the hierarchical path to the property value to be set. * @param propertyValue the property value to be set. * @return a copy of this Feature with the given property value set. * @throws NullPointerException if any argument is {@code null}. */ default Feature setProperty(final CharSequence pointer, final String propertyValue) { return setProperty(JsonPointer.of(pointer), JsonValue.of(propertyValue)); }
/** * Sets the value of a property which is referred by the given JSON Pointer. * * @param pointer defines the hierarchical path to the property value to be set. * @param propertyValue the property value to be set. * @return a copy of this Feature with the given property value set. * @throws NullPointerException if any argument is {@code null}. */ default Feature setProperty(final CharSequence pointer, final long propertyValue) { return setProperty(JsonPointer.of(pointer), JsonValue.of(propertyValue)); }
/** * Sets the value of a property which is referred by the given JSON Pointer. * * @param pointer defines the hierarchical path to the property value to be set. * @param propertyValue the property value to be set. * @return a copy of this Feature with the given property value set. * @throws NullPointerException if any argument is {@code null}. */ default Feature setProperty(final CharSequence pointer, final double propertyValue) { return setProperty(JsonPointer.of(pointer), JsonValue.of(propertyValue)); }
/** * Sets the value of a property which is referred by the given JSON Pointer. * * @param pointer defines the hierarchical path to the property value to be set. * @param propertyValue the property value to be set. * @return a copy of this Feature with the given property value set. * @throws NullPointerException if any argument is {@code null}. */ default Feature setProperty(final CharSequence pointer, final boolean propertyValue) { return setProperty(JsonPointer.of(pointer), JsonValue.of(propertyValue)); }
/** * Sets the value of a property which is referred by the given JSON Pointer. * * @param pointer defines the hierarchical path to the property value to be set. * @param propertyValue the property value to be set. * @return a copy of this Feature with the given property value set. * @throws NullPointerException if any argument is {@code null}. */ default Feature setProperty(final CharSequence pointer, final double propertyValue) { return setProperty(JsonPointer.of(pointer), JsonValue.of(propertyValue)); }
/** * Sets the given attribute on a copy of this Thing. * * @param attributePath the hierarchical path to the attribute value. * @param attributeValue the attribute value to be set. * @return a copy of this Thing with the given attribute. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code attributePath} is empty. */ default Thing setAttribute(final CharSequence attributePath, final String attributeValue) { return setAttribute(JsonPointer.of(attributePath), JsonValue.of(attributeValue)); }
/** * Sets the value of a property which is referred by the given JSON Pointer. * * @param pointer defines the hierarchical path to the property value to be set. * @param propertyValue the property value to be set. * @return a copy of this Feature with the given property value set. * @throws NullPointerException if any argument is {@code null}. */ default Feature setProperty(final CharSequence pointer, final boolean propertyValue) { return setProperty(JsonPointer.of(pointer), JsonValue.of(propertyValue)); }
/** * Sets the given attribute on a copy of this Thing. * * @param attributePath the hierarchical path to the attribute value. * @param attributeValue the attribute value to be set. * @return a copy of this Thing with the given attribute. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code attributePath} is empty. */ default Thing setAttribute(final CharSequence attributePath, final boolean attributeValue) { return setAttribute(JsonPointer.of(attributePath), JsonValue.of(attributeValue)); }
/** * Sets the given attribute on a copy of this Thing. * * @param attributePath the hierarchical path to the attribute value. * @param attributeValue the attribute value to be set. * @return a copy of this Thing with the given attribute. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code attributePath} is empty. */ default Thing setAttribute(final CharSequence attributePath, final long attributeValue) { return setAttribute(JsonPointer.of(attributePath), JsonValue.of(attributeValue)); }
@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 static void injectMessagePayload(final JsonObjectBuilder messageBuilder, final Predicate<JsonField> predicate, final String encodedString, final MessageHeaders messageHeaders) { MessageCommandSizeValidator.getInstance().ensureValidSize(encodedString::length, () -> messageHeaders); messageBuilder.set(MessageCommand.JsonFields.JSON_MESSAGE_PAYLOAD, JsonValue.of(encodedString), predicate); }
private static void injectMessagePayload(final JsonObjectBuilder messageBuilder, final Predicate<JsonField> predicate, final String encodedString, final MessageHeaders messageHeaders) { MessageCommandSizeValidator.getInstance().ensureValidSize(encodedString::length, () -> messageHeaders); messageBuilder.set(MessageCommand.JsonFields.JSON_MESSAGE_PAYLOAD, JsonValue.of(encodedString), predicate); }
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)); }