/** * Sets a message which points to the name of the missing field. Thus if this method is called, {@link #message} * should not be called. * * @param missingFieldName the name of the missing field. * @return this builder to allow method chaining. */ public Builder fieldName(final CharSequence missingFieldName) { message(MessageFormat.format(MESSAGE_TEMPLATE, missingFieldName)); return this; }
/** * Sets a message which points to the name of the missing field. Thus if this method is called, {@link #message} * should not be called. * * @param missingFieldName the name of the missing field. * @return this builder to allow method chaining. */ public Builder fieldName(final CharSequence missingFieldName) { message(MessageFormat.format(MESSAGE_TEMPLATE, missingFieldName)); return this; }
JsonMissingFieldException.newBuilder().message(getMessage(jsonObject)).build(), dittoHeaders));
JsonMissingFieldException.newBuilder().message(getMessage(jsonObject)).build(), dittoHeaders));
/** * Creates a new {@code Subject} object from the specified JSON object. * * @param subjectIssuerWithId the Subject issuer + Subject ID (separated with a "{@value * SubjectId#ISSUER_DELIMITER}" of the Subject to be created. * @param jsonObject a JSON object which provides the data for the Subject to be created. * @return a new Subject which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws DittoJsonException if {@code jsonObject} * <ul> * <li>is empty,</li> * <li>contains only a field with the schema version</li> * <li>or it contains more than two fields.</li> * </ul> */ public static Subject fromJson(final CharSequence subjectIssuerWithId, final JsonObject jsonObject) { checkNotNull(subjectIssuerWithId, "Subject ID"); checkNotNull(jsonObject, "JSON object"); final String subjectTypeValue = jsonObject.getValue(JsonFields.TYPE) .orElseThrow(() -> new DittoJsonException(JsonMissingFieldException.newBuilder() .message("The 'type' for the 'subject' is missing.") .build())); return of(SubjectId.newInstance(subjectIssuerWithId), ImmutableSubjectType.of(subjectTypeValue)); }
/** * Creates a new {@code Resource} object from the specified JSON object. * * @param jsonObject a JSON object which provides the data for the Resource to be created. * @return a new Resource which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws DittoJsonException if {@code jsonObject} * <ul> * <li>is empty,</li> * <li>contains only a field with the schema version</li> * <li>or it contains more than two fields.</li> * </ul> */ public static Resource fromJson(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object"); return jsonObject.stream() .filter(field -> !Objects.equals(field.getKey(), JsonSchemaVersion.getJsonKey())) .findFirst() .map(field -> of(ResourceKey.newInstance(field.getKeyName()), field.getValue())) .orElseThrow(() -> new DittoJsonException(JsonMissingFieldException.newBuilder() .message("The JSON object for the 'resource' is missing.") .build())); }
/** * Creates a new {@code AclEntry} object from the specified JSON object. If, for any reason, the specified JSON * object contains more than one field with Authorization Subject/permissions pairs only the first field is used * while all remaining fields are ignored. * * @param jsonObject a JSON object which provides the data for the ACL entry to be created. * @return a new ACL entry which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws DittoJsonException if {@code jsonObject} <ul> <li>is empty,</li> <li>contains only a field with the schema * version</li> <li>or it contains more than two fields.</li> </ul> */ public static AclEntry fromJson(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object"); return jsonObject.stream() .filter(field -> !Objects.equals(field.getKey(), JsonSchemaVersion.getJsonKey())) .findFirst() .map(field -> ImmutableAclEntry.of(field.getKey(), field.getValue())) .orElseThrow(() -> new DittoJsonException(JsonMissingFieldException.newBuilder() .message("The JSON object for 'aclEntry' is missing.") .build())); }
/** * Creates a new {@code AclEntry} object from the specified JSON object. If, for any reason, the specified JSON * object contains more than one field with Authorization Subject/permissions pairs only the first field is used * while all remaining fields are ignored. * * @param jsonObject a JSON object which provides the data for the ACL entry to be created. * @return a new ACL entry which is initialised with the extracted data from {@code jsonObject}. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws DittoJsonException if {@code jsonObject} <ul> <li>is empty,</li> <li>contains only a field with the schema * version</li> <li>or it contains more than two fields.</li> </ul> */ public static AclEntry fromJson(final JsonObject jsonObject) { checkNotNull(jsonObject, "JSON object"); return jsonObject.stream() .filter(field -> !Objects.equals(field.getKey(), JsonSchemaVersion.getJsonKey())) .findFirst() .map(field -> ImmutableAclEntry.of(field.getKey(), field.getValue())) .orElseThrow(() -> new DittoJsonException(JsonMissingFieldException.newBuilder() .message("The JSON object for 'aclEntry' is missing.") .build())); }