diff --git a/README.md b/README.md index aa247ee1..4f3de655 100644 --- a/README.md +++ b/README.md @@ -159,8 +159,7 @@ public interface API { } ``` -ℹ️ If your REST endpoint returns an empty body, you need to specify `Observable` as return value rather than `Observable` because ["Nulls are not allowed in \[RxJava\] 2.x."](https://github.com/ReactiveX/RxJava/issues/5775#issuecomment-353544736). -ℹ️ If you are working with `Call`s you can safely use `Call` (or `Call`) if you want. +ℹ️ If your REST endpoint returns an empty body, you need to specify `Observable` / `Call` as return value rather than `Observable` / `Call` because ["Nulls are not allowed in \[RxJava\] 2.x."](https://github.com/ReactiveX/RxJava/issues/5775#issuecomment-353544736). You might instantiate your Retrofit `API` by using something like this: diff --git a/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudAPI.java b/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudAPI.java index 24bdfa51..0ae5d7be 100644 --- a/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudAPI.java +++ b/lib/src/main/java/com/nextcloud/android/sso/api/NextcloudAPI.java @@ -132,6 +132,8 @@ public T performRequestV2(final @NonNull Type type, NextcloudRequest request } public T convertStreamToTargetEntity(InputStream inputStream, Type targetEntity) throws IOException { + ensureTypeNotVoid(targetEntity); + final T result; try (InputStream os = inputStream; Reader targetReader = new InputStreamReader(os)) { diff --git a/lib/src/main/java/com/nextcloud/android/sso/helper/Retrofit2Helper.java b/lib/src/main/java/com/nextcloud/android/sso/helper/Retrofit2Helper.java index 1838f111..6882c447 100644 --- a/lib/src/main/java/com/nextcloud/android/sso/helper/Retrofit2Helper.java +++ b/lib/src/main/java/com/nextcloud/android/sso/helper/Retrofit2Helper.java @@ -50,7 +50,7 @@ private Retrofit2Helper() { } public static Call WrapInCall(final NextcloudAPI nextcloudAPI, final NextcloudRequest nextcloudRequest, final Type resType) { - return new Call() { + return new Call<>() { /** * Execute synchronous @@ -134,83 +134,4 @@ private Response convertExceptionToResponse(int statusCode, String errorMessa } }; } - - /** - * - * @param success if true, a Response.success will be returned, otherwise Response.error(520) - */ - public static Call wrapEmptyResponseCall(final boolean success) { - return new Call<>() { - @NonNull - @Override - public Response execute() { - if (success) { - return Response.success(null); - } else { - return Response.error(520, emptyResponseBody); - } - } - - @Override - public void enqueue(@NonNull Callback callback) { - if (success) { - callback.onResponse(this, Response.success(null)); - } else { - callback.onResponse(this, Response.error(520, emptyResponseBody)); - } - } - - @Override - public boolean isExecuted() { - return true; - } - - @Override - public void cancel() { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - public boolean isCanceled() { - return false; - } - - @NonNull - @Override - public Call clone() { - throw new UnsupportedOperationException("Not implemented"); - } - - @NonNull - @Override - public Request request() { - throw new UnsupportedOperationException("Not implemented"); - } - - @NonNull - @Override - public Timeout timeout() { - throw new UnsupportedOperationException("Not implemented"); - } - }; - - } - - private final static ResponseBody emptyResponseBody = new ResponseBody() { - @Override - public MediaType contentType() { - return null; - } - - @Override - public long contentLength() { - return 0; - } - - @Override - public BufferedSource source() { - return null; - } - }; - }