class ImmutableResource implements Resource {

    public static Resource of(final ResourceKey resourceKey, final JsonValue jsonValue) {
        checkNotNull(jsonValue, "JSON value");

        final EffectedPermissions effectedPermissions = Optional.of(jsonValue)
                .filter(JsonValue::isObject)
                .map(JsonValue::asObject)
                .map(object -> wrapJsonRuntimeException(() -> ImmutableEffectedPermissions.fromJson(object)))
                .orElseThrow(() -> new DittoJsonException(JsonParseException.newBuilder()
                        .message("The JSON object for the 'permissions' (grant/revoke) of the 'resource' '" +
                                resourceKey + "' is missing or not an object.")
                        .build()));

        return of(resourceKey, effectedPermissions);
    }

    private  ImmutableResource(final ResourceKey theResourceKey, final EffectedPermissions theEffectedPermissions);

}