Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 240a1c1e authored by Mario Đanić's avatar Mario Đanić Committed by GitHub
Browse files

Merge pull request #115 from nextcloud/bugfix/incorrectServerResponse

Make OCSResponse a generic class, not just a class with geric method
parents 460a9bf0 c0baae36
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -45,14 +45,13 @@ import java.lang.reflect.Type;
 */
public abstract class OCSRemoteOperation extends RemoteOperation {

    public <T> ServerResponse<T> getServerResponse(HttpMethodBase method) throws IOException {
    public <T> T getServerResponse(HttpMethodBase method, TypeToken<T> type) throws IOException {
        String response = method.getResponseBodyAsString();
        JsonParser parser = new JsonParser();
        JsonElement element = parser.parse(response);

        Gson gson = new Gson();
        Type type = new TypeToken<T>(){}.getType();

        return gson.fromJson(element, type);
        return gson.fromJson(element, type.getType());
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
 */
package com.owncloud.android.lib.resources.users;

import com.google.gson.reflect.TypeToken;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
@@ -62,7 +63,7 @@ public class GetPrivateKeyOperation extends OCSRemoteOperation {
            int status = client.executeMethod(getMethod, SYNC_READ_TIMEOUT, SYNC_CONNECTION_TIMEOUT);

            if (status == HttpStatus.SC_OK) {
                ServerResponse<PrivateKey> serverResponse = getServerResponse(getMethod);
                ServerResponse<PrivateKey> serverResponse = getServerResponse(getMethod, new TypeToken<ServerResponse<PrivateKey>>(){});

                result = new RemoteOperationResult(true, getMethod);
                ArrayList<Object> keys = new ArrayList<>();
+2 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ package com.owncloud.android.lib.resources.users;

import android.text.TextUtils;

import com.google.gson.reflect.TypeToken;
import com.owncloud.android.lib.common.OwnCloudBasicCredentials;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.UserInfo;
@@ -118,7 +119,7 @@ public class GetRemoteUserInfoOperation extends OCSRemoteOperation {
                String response = get.getResponseBodyAsString();
                Log_OC.d(TAG, "Successful response: " + response);

                ServerResponse<UserInfo> ocsResponse = getServerResponse(get);
                ServerResponse<UserInfo> ocsResponse = getServerResponse(get, new TypeToken<ServerResponse<UserInfo>>(){});

                UserInfo userInfo = ocsResponse.getOcs().getData();