protected static FeatureProperties featurePropertiesFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(ThingsModelFactory::newFeatureProperties) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private static Instant tryToParseModified(final CharSequence dateTime) { try { return Instant.parse(dateTime); } catch (final DateTimeParseException e) { throw new JsonParseException("The JSON object's field '_modified' is not in ISO-8601 format as expected"); } }
protected static Thing thingFrom(final Adaptable adaptable) { return adaptable.getPayload().getValue() .map(JsonValue::asObject) .map(ThingsModelFactory::newThing) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
@Override protected JsonParseException doBuild(final String errorCode, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new JsonParseException(message, description, cause, href); }
protected static Attributes attributesFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(ThingsModelFactory::newAttributes) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
@Override protected JsonParseException doBuild(final String errorCode, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new JsonParseException(message, description, cause, href); }
protected static JsonArray thingsArrayFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .filter(JsonValue::isArray) .map(JsonValue::asArray) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private void validateCommandResponseType() { final String actualCommandResponseType = jsonObject.getValueOrThrow(CommandResponse.JsonFields.TYPE); if (!expectedCommandResponseType.equals(actualCommandResponseType)) { final String msgPattern = "Command Response JSON was not a <{0}> command response but a <{1}>!"; final String msg = MessageFormat.format(msgPattern, expectedCommandResponseType, actualCommandResponseType); throw new DittoJsonException(new JsonParseException(msg)); } }
protected static Features featuresFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(ThingsModelFactory::newFeatures) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private void checkValueType(final JsonValue jsonValue) { requireNonNull(jsonValue, "The JsonValue to be mapped must not be (Java) null!"); if (!hasExpectedValueType(jsonValue)) { final String msgPattern = "Value <{0}> for <{1}> is not of type <{2}>!"; final String message = MessageFormat.format(msgPattern, jsonValue, pointer, valueType.getSimpleName()); throw new JsonParseException(message); } }
protected static FeatureDefinition featureDefinitionFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asArray) .map(ThingsModelFactory::newFeatureDefinition) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private void validateCommandResponseType() { final String actualCommandResponseType = jsonObject.getValueOrThrow(CommandResponse.JsonFields.TYPE); if (!expectedCommandResponseType.equals(actualCommandResponseType)) { final String msgPattern = "Command Response JSON was not a <{0}> command response but a <{1}>!"; final String msg = MessageFormat.format(msgPattern, expectedCommandResponseType, actualCommandResponseType); throw new DittoJsonException(new JsonParseException(msg)); } }
protected static Thing thingFrom(final Adaptable adaptable) { return adaptable.getPayload().getValue() .map(JsonValue::asObject) .map(ThingsModelFactory::newThing) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private void checkValueType(final JsonValue jsonValue) { requireNonNull(jsonValue, "The JsonValue to be mapped must not be (Java) null!"); if (!hasExpectedValueType(jsonValue)) { final String msgPattern = "Value <{0}> for <{1}> is not of type <{2}>!"; final String message = MessageFormat.format(msgPattern, jsonValue, pointer, valueType.getSimpleName()); throw new JsonParseException(message); } }
protected static FeatureProperties featurePropertiesFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(ThingsModelFactory::newFeatureProperties) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private static Instant tryToParseModified(final CharSequence dateTime) { try { return Instant.parse(dateTime); } catch (final DateTimeParseException e) { throw new JsonParseException("The JSON object's field '" + JsonFields.MODIFIED.getPointer() + "' " + "is not in ISO-8601 format as expected"); } }
protected static FeatureDefinition featureDefinitionFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asArray) .map(ThingsModelFactory::newFeatureDefinition) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
/** * Reads the given string and creates a JSON value based on the read data. The actual type of this JSON value is * unknown but can be obtained by invoking the {@code is...} methods. * * @param jsonString the JSON document to read. * @return a JSON value representing the read document. This value can be a JSON literal, a JSON object and so on. * @throws NullPointerException if {@code jsonString} is empty. * @throws JsonParseException if {@code jsonString} is empty or if it is no valid JSON. */ public static JsonValue readFrom(final String jsonString) { requireNonNull(jsonString, "The JSON string to read from must not be null!"); if (jsonString.isEmpty()) { throw new JsonParseException("The JSON string to read from must not be empty!"); } return JsonValueParser.fromString().apply(jsonString); }
protected static AccessControlList aclFrom(final Adaptable adaptable) { return adaptable.getPayload() .getValue() .map(JsonValue::asObject) .map(AccessControlListModelFactory::newAcl) .orElseThrow(() -> JsonParseException.newBuilder().build()); }
private static List<String> thingsIdsFrom(final Adaptable adaptable) { final JsonArray array = adaptable.getPayload() .getValue() .filter(JsonValue::isObject) .map(JsonValue::asObject) .orElseThrow(() -> new JsonParseException("Adaptable payload was non existing or no JsonObject")) .getValue(RetrieveThings.JSON_THING_IDS) .filter(JsonValue::isArray) .map(JsonValue::asArray) .orElseThrow(() -> new JsonParseException("Could not map 'thingIds' value to expected JsonArray")); return array.stream() .map(JsonValue::asString) .collect(Collectors.toList()); }