@Override protected JsonMissingFieldException doBuild(final String errorCode, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new JsonMissingFieldException(message, description, cause, href); }
@Override protected String resolveType(final JsonObject jsonObject) { final Supplier<String> command = () -> jsonObject.getValue(Command.JsonFields.ID) .map(cmd -> getTypePrefix() + cmd) // and transform to V2 format // fail if "command" also is not present .orElseThrow(() -> JsonMissingFieldException.newBuilder() .fieldName(Command.JsonFields.TYPE.getPointer().toString()) .build()); // if type was not present (was included in V2) take "command" instead return jsonObject.getValue(Command.JsonFields.TYPE).orElseGet(command); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw JsonMissingFieldException.newBuilder().fieldName(fieldDefinition.getPointer()).build(); }
@Override protected JsonMissingFieldException doBuild(final String errorCode, @Nullable final String message, @Nullable final String description, @Nullable final Throwable cause, @Nullable final URI href) { return new JsonMissingFieldException(message, description, cause, href); }
@Override protected String resolveType(final JsonObject jsonObject) { final Supplier<String> command = () -> jsonObject.getValue(Command.JsonFields.ID) .map(cmd -> getTypePrefix() + cmd) // and transform to V2 format // fail if "command" also is not present .orElseThrow(() -> JsonMissingFieldException.newBuilder() .fieldName(Command.JsonFields.TYPE.getPointer().toString()) .build()); // if type was not present (was included in V2) take "command" instead return jsonObject.getValue(Command.JsonFields.TYPE).orElseGet(command); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { return getValue(fieldDefinition).orElseThrow(() -> new JsonMissingFieldException(fieldDefinition)); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw JsonMissingFieldException.newBuilder().fieldName(fieldDefinition.getPointer()).build(); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw new JsonMissingFieldException(fieldDefinition.getPointer()); }
private static String getMessage(final JsonObject jsonObject) { return jsonObject.getValue(DittoJsonException.JsonFields.MESSAGE) .orElseThrow(() -> JsonMissingFieldException.newBuilder() .fieldName(DittoRuntimeException.JsonFields.MESSAGE.getPointer().toString()).build()); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw new JsonMissingFieldException(fieldDefinition.getPointer()); }
private static String getMessage(final JsonObject jsonObject) { return jsonObject.getValue(DittoJsonException.JsonFields.MESSAGE) .orElseThrow(() -> JsonMissingFieldException.newBuilder() .fieldName(DittoRuntimeException.JsonFields.MESSAGE.getPointer().toString()).build()); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw new JsonMissingFieldException(fieldDefinition.getPointer()); }
@Override protected String resolveType(final JsonObject jsonObject) { return jsonObject.getValue(DittoRuntimeException.JsonFields.ERROR_CODE) .orElseThrow(() -> JsonMissingFieldException.newBuilder() .fieldName(DittoRuntimeException.JsonFields.ERROR_CODE.getPointer().toString()) .build()); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { return getValue(fieldDefinition).orElseThrow(() -> new JsonMissingFieldException(fieldDefinition)); }
@Override protected String resolveType(final JsonObject jsonObject) { return jsonObject.getValue(Command.JsonFields.TYPE) .orElseThrow(() -> JsonMissingFieldException.newBuilder() .fieldName(Command.JsonFields.TYPE.getPointer().toString()) .build()); }
@Override public <T> T getValueOrThrow(final JsonFieldDefinition<T> fieldDefinition) { throw new JsonMissingFieldException(fieldDefinition.getPointer()); }
@Override protected String resolveType(final JsonObject jsonObject) { return jsonObject.getValue(DittoRuntimeException.JsonFields.ERROR_CODE) .orElseThrow(() -> JsonMissingFieldException.newBuilder() .fieldName(DittoRuntimeException.JsonFields.ERROR_CODE.getPointer().toString()) .build()); }
@Override protected String resolveType(final JsonObject jsonObject) { /* * If type was not present (was included in V2) take "event" instead and transform to V2 format. * Fail if "event" also is not present. */ return jsonObject.getValue(Event.JsonFields.TYPE) .orElseGet(() -> extractTypeV1(jsonObject) .orElseThrow(() -> new JsonMissingFieldException(Event.JsonFields.TYPE))); }
private static long revisionFrom(final Adaptable adaptable) { return adaptable.getPayload().getRevision().orElseThrow(() -> JsonMissingFieldException.newBuilder() .fieldName(Payload.JsonFields.REVISION.getPointer().toString()).build()); }
private void validateCommandType() { final JsonFieldDefinition<String> typeFieldDefinition = Command.JsonFields.TYPE; final Optional<String> actualCommandTypeOptional = jsonObject.getValue(typeFieldDefinition); final String actualCommandType = actualCommandTypeOptional.orElseGet(() -> { // "type" was introduced in V2, if not present, take "command" instead. final String commandTypePrefix = expectedCommandType.split(":")[0]; return jsonObject.getValue(Command.JsonFields.ID) .map(id -> commandTypePrefix + ':' + id) .orElseThrow(() -> new JsonMissingFieldException(typeFieldDefinition)); }); if (!expectedCommandType.equals(actualCommandType)) { final String msgPattern = "Command JSON was not a <{0}> command but a <{1}>!"; final String msg = MessageFormat.format(msgPattern, expectedCommandType, actualCommandType); throw new DittoJsonException(new JsonParseException(msg)); } }