/** * Returns a JSON string representation of this object. The content of the result is determined by the given * pointer. * * @param pointer determines the field to be included in the JSON representation. * @return a JSON string representation of this object. * @throws NullPointerException if {@code pointer} is {@code null}. * @see #toJson(JsonPointer) */ default String toJsonString(final JsonPointer pointer) { return toJson(pointer).toString(); }
/** * Returns a JSON string representation of this object. * * @return a JSON string representation of this object. * @see #toJson() */ default String toJsonString() { return toJson().toString(); }
/** * Returns a JSON string representation of this object. The content of the result is determined by the given * predicate. * * @param predicate determines the content of the result. * @return a JSON string representation of this object. * @throws NullPointerException if {@code predicate} is {@code null}. * @see #toJson(Predicate) */ default String toJsonString(final Predicate<T> predicate) { return toJson(predicate).toString(); }
/** * Returns a JSON string representation of this object. The content of the result is determined by the given * predicate. * * @param predicate determines the content of the result. * @return a JSON string representation of this object. * @throws NullPointerException if {@code predicate} is {@code null}. * @see #toJson(Predicate) */ default String toJsonString(final Predicate<T> predicate) { return toJson(predicate).toString(); }
/** * Returns a JSON string representation of this object. The content of the result is determined by the given * pointer. * * @param pointer determines the field to be included in the JSON representation. * @return a JSON string representation of this object. * @throws NullPointerException if {@code pointer} is {@code null}. * @see #toJson(JsonPointer) */ default String toJsonString(final JsonPointer pointer) { return toJson(pointer).toString(); }
@Override protected String createStringRepresentation() { return JsonFactory.nullLiteral().toString(); }
@Override public byte[] serialize(T t) { try { return toJson(t).toString().getBytes(StandardCharsets.UTF_8); } catch (final SerializationException se) { throw se; } catch (final Exception e) { throw new SerializationException("Unable to serialize object of type " + t.getClass().getName() + " to JSON: " + e.getMessage(), e); } }
@Override public byte[] serialize(T t) { try { return toJson(t).toString().getBytes(StandardCharsets.UTF_8); } catch (final SerializationException se) { throw se; } catch (final Exception e) { throw new SerializationException("Unable to serialize object of type " + t.getClass().getName() + " to JSON: " + e.getMessage(), e); } }
/** * 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 Function<Jsonifiable<?>, PlainJson> supplyPlainJsonFromRetrieveThingResponse() { return jsonifiable -> { if (jsonifiable instanceof RetrieveThingResponse) { final RetrieveThingResponse response = (RetrieveThingResponse) jsonifiable; final String json = response.getEntityPlainString().orElseGet(() -> response.getEntity(response.getImplementedSchemaVersion()).toString()); return PlainJson.of(response.getId(), json); } else { return null; } }; }
@Override public QueryThingsResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); final SearchResult searchResult = SearchModelFactory.newSearchResult(entity.toString()); return of(searchResult, getDittoHeaders()); }
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; }
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 QueryThingsResponse setEntity(final JsonValue entity) { checkNotNull(entity, "entity"); final SearchResult searchResult = SearchModelFactory.newSearchResult(entity.toString()); return of(searchResult, getDittoHeaders()); }
private ModifyAttribute(final JsonPointer attributePointer, final JsonValue attributeValue, final String thingId, final DittoHeaders dittoHeaders) { super(TYPE, dittoHeaders); ThingIdValidator.getInstance().accept(thingId, dittoHeaders); this.thingId = thingId; this.attributePointer = checkAttributePointer(attributePointer, dittoHeaders); this.attributeValue = checkNotNull(attributeValue, "new attribute"); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> attributeValue.toString().length(), () -> dittoHeaders); }
private ModifyAttribute(final JsonPointer attributePointer, final JsonValue attributeValue, final String thingId, final DittoHeaders dittoHeaders) { super(TYPE, dittoHeaders); ThingIdValidator.getInstance().accept(thingId, dittoHeaders); this.thingId = thingId; this.attributePointer = checkAttributePointer(attributePointer, dittoHeaders); this.attributeValue = checkNotNull(attributeValue, "new attribute"); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> attributeValue.toString().length(), () -> dittoHeaders); }
private ModifyFeatureProperty(final String thingId, final String featureId, final JsonPointer propertyPointer, final JsonValue propertyValue, final DittoHeaders dittoHeaders) { super(TYPE, dittoHeaders); ThingIdValidator.getInstance().accept(thingId, dittoHeaders); this.thingId = thingId; this.featureId = checkNotNull(featureId, "Feature ID"); this.propertyPointer = checkNotNull(propertyPointer, "Property JsonPointer"); this.propertyValue = checkNotNull(propertyValue, "Property Value"); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> propertyValue.toString().length(), () -> dittoHeaders); }
private ModifyFeatureProperty(final String thingId, final String featureId, final JsonPointer propertyPointer, final JsonValue propertyValue, final DittoHeaders dittoHeaders) { super(TYPE, dittoHeaders); ThingIdValidator.getInstance().accept(thingId, dittoHeaders); this.thingId = thingId; this.featureId = checkNotNull(featureId, "Feature ID"); this.propertyPointer = checkNotNull(propertyPointer, "Property JsonPointer"); this.propertyValue = checkNotNull(propertyValue, "Property Value"); ThingCommandSizeValidator.getInstance().ensureValidSize(() -> propertyValue.toString().length(), () -> dittoHeaders); }