/** * Constructs a new {@code JsonMissingFieldException} object for the JsonPointer of the specified * JsonFieldDefinition. * * @param fieldDefinition provides the JsonPointer which refers to the missing field. * @throws NullPointerException if {@code jsonFieldDefinition} is {@code null}. */ public JsonMissingFieldException(final JsonFieldDefinition<?> fieldDefinition) { this(requireNonNull(fieldDefinition, "The JSON Field Definition must not be null!").getPointer()); }
private static JsonObject getPayload(final JsonObject sourceJsonObject) { final JsonObject result; final Optional<JsonValue> payloadJsonOptional = sourceJsonObject.getValue(JSON_PAYLOAD); if (payloadJsonOptional.isPresent()) { final JsonValue payloadJson = payloadJsonOptional.get(); if (!payloadJson.isObject()) { final String msgPattern = "Value <{0}> for <{1}> was not of type <{2}>!"; final String simpleName = JSON_PAYLOAD.getValueType().getSimpleName(); final String msg = MessageFormat.format(msgPattern, payloadJson, JSON_PAYLOAD.getPointer(), simpleName); throw new DittoJsonException(new IllegalArgumentException(msg)); } else { result = payloadJson.asObject(); } } else { result = JsonFactory.newObject(); } return result; }
@Override public boolean isMarkedAs(final JsonFieldMarker fieldMarker, final JsonFieldMarker... furtherFieldMarkers) { return null != definition && definition.isMarkedAs(fieldMarker, furtherFieldMarkers); }
/** * Constructs a new {@code JsonMissingFieldException} object for the JsonPointer of the specified * JsonFieldDefinition. * * @param fieldDefinition provides the JsonPointer which refers to the missing field. * @throws NullPointerException if {@code jsonFieldDefinition} is {@code null}. */ public JsonMissingFieldException(final JsonFieldDefinition<?> fieldDefinition) { this(requireNonNull(fieldDefinition, "The JSON Field Definition must not be null!").getPointer()); }
private static JsonObject getPayload(final JsonObject sourceJsonObject) { final JsonObject result; final Optional<JsonValue> payloadJsonOptional = sourceJsonObject.getValue(JSON_PAYLOAD); if (payloadJsonOptional.isPresent()) { final JsonValue payloadJson = payloadJsonOptional.get(); if (!payloadJson.isObject()) { final String msgPattern = "Value <{0}> for <{1}> was not of type <{2}>!"; final String simpleName = JSON_PAYLOAD.getValueType().getSimpleName(); final String msg = MessageFormat.format(msgPattern, payloadJson, JSON_PAYLOAD.getPointer(), simpleName); throw new DittoJsonException(new IllegalArgumentException(msg)); } else { result = payloadJson.asObject(); } } else { result = JsonFactory.newObject(); } return result; }
@Override public boolean isMarkedAs(final JsonFieldMarker fieldMarker, final JsonFieldMarker... furtherFieldMarkers) { return null != definition && definition.isMarkedAs(fieldMarker, furtherFieldMarkers); }
private void addFieldDefinition(@Nullable final JsonFieldDefinition fieldDefinition) { if (null != fieldDefinition) { addPointer(fieldDefinition.getPointer()); } }
@Override public ImmutableJsonObjectBuilder remove(final JsonFieldDefinition fieldDefinition) { requireNonNull(fieldDefinition, "The field definition must not be null!"); return remove(fieldDefinition.getPointer()); }
@Override public JsonFieldSelectorBuilder removeFieldDefinition(@Nullable final JsonFieldDefinition fieldDefinition) { if (null == fieldDefinition) { return this; } return removePointer(fieldDefinition.getPointer()); }
@Override public ImmutableJsonObjectBuilder remove(final JsonFieldDefinition fieldDefinition) { requireNonNull(fieldDefinition, "The field definition must not be null!"); return remove(fieldDefinition.getPointer()); }
@Override public JsonFieldSelectorBuilder removeFieldDefinition(@Nullable final JsonFieldDefinition fieldDefinition) { if (null == fieldDefinition) { return this; } return removePointer(fieldDefinition.getPointer()); }
private void addFieldDefinition(@Nullable final JsonFieldDefinition fieldDefinition) { if (null != fieldDefinition) { addPointer(fieldDefinition.getPointer()); } }
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"); } }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw new JsonMissingFieldException(fieldDefinition.getPointer()); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw new JsonMissingFieldException(fieldDefinition.getPointer()); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw new JsonMissingFieldException(fieldDefinition.getPointer()); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw new JsonMissingFieldException(fieldDefinition.getPointer()); }
/** * Returns a new JSON field selector which is based on pointers of the given {@link JsonFieldDefinition}(s). * * @param fieldDefinition the JSON field definition of the returned field selector. * @param furtherFieldDefinitions additional JSON field definitions of the returned field selector. * @return a new JSON field selector. * @throws NullPointerException if any argument is {@code null}. */ public static JsonFieldSelector newFieldSelector(final JsonFieldDefinition fieldDefinition, final JsonFieldDefinition... furtherFieldDefinitions) { requireNonNull(fieldDefinition, "The JSON field definition must not be null!"); requireNonNull(furtherFieldDefinitions, "The optional JSON field definitions must not be null!"); final Collection<JsonPointer> pointers = new LinkedHashSet<>(1 + furtherFieldDefinitions.length); pointers.add(fieldDefinition.getPointer()); for (final JsonFieldDefinition furtherFieldDefinition : furtherFieldDefinitions) { pointers.add(furtherFieldDefinition.getPointer()); } return newFieldSelector(pointers); }
/** * Returns a new JSON field selector which is based on pointers of the given {@link JsonFieldDefinition}(s). * * @param fieldDefinition the JSON field definition of the returned field selector. * @param furtherFieldDefinitions additional JSON field definitions of the returned field selector. * @return a new JSON field selector. * @throws NullPointerException if any argument is {@code null}. */ public static JsonFieldSelector newFieldSelector(final JsonFieldDefinition fieldDefinition, final JsonFieldDefinition... furtherFieldDefinitions) { requireNonNull(fieldDefinition, "The JSON field definition must not be null!"); requireNonNull(furtherFieldDefinitions, "The optional JSON field definitions must not be null!"); final Collection<JsonPointer> pointers = new LinkedHashSet<>(1 + furtherFieldDefinitions.length); pointers.add(fieldDefinition.getPointer()); for (final JsonFieldDefinition furtherFieldDefinition : furtherFieldDefinitions) { pointers.add(furtherFieldDefinition.getPointer()); } return newFieldSelector(pointers); }
@SuppressWarnings("squid:CallToDeprecatedMethod") private static JsonObject migrateId(final JsonObject jsonObject) { return jsonObject.getValue(Event.JsonFields.ID) .map(name -> name.replaceFirst("thing", "")) .map(Introspector::decapitalize) .map(name -> ThingEvent.TYPE_PREFIX + name) .map(JsonValue::of) .map(type -> jsonObject.setValue(Event.JsonFields.TYPE.getPointer(), type)) .orElse(jsonObject); }