Skip to content

Commit a11ac23

Browse files
committed
fix!: TypeReference issue for generic type
1 parent e5f8716 commit a11ac23

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/main/java/mobi/appcent/medusa/store/MedusaSdkClient.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
package mobi.appcent.medusa.store;
1414

15+
import com.google.gson.reflect.TypeToken;
1516
import com.squareup.okhttp.*;
1617
import com.squareup.okhttp.internal.http.HttpMethod;
1718
import com.squareup.okhttp.logging.HttpLoggingInterceptor;
1819
import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level;
1920
import mobi.appcent.medusa.store.auth.*;
21+
import mobi.appcent.medusa.store.common.TypeReference;
2022
import okio.BufferedSink;
2123
import okio.Okio;
2224
import org.threeten.bp.LocalDate;
@@ -718,7 +720,8 @@ public File prepareDownloadFile(Response response) throws IOException {
718720
* @return ApiResponse<T>
719721
*/
720722
public <T> ApiResponse<T> execute(Call call) throws ApiException {
721-
return execute(call, null);
723+
TypeReference<T> typeReference = new TypeReference<T>() {};
724+
return execute(call, typeReference.getType());
722725
}
723726

724727
/**
@@ -732,7 +735,7 @@ public <T> ApiResponse<T> execute(Call call) throws ApiException {
732735
* when returnType is null.
733736
* @throws ApiException If fail to execute the call
734737
*/
735-
public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
738+
private <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiException {
736739
try {
737740
Response response = call.execute();
738741
T data = handleResponse(response, returnType);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package mobi.appcent.medusa.store.common;
2+
3+
import java.lang.reflect.ParameterizedType;
4+
import java.lang.reflect.Type;
5+
6+
public abstract class TypeReference<T> {
7+
8+
public TypeReference() {}
9+
10+
public Type getType() {
11+
Type mySuperclass = this.getClass().getGenericSuperclass();
12+
return ((ParameterizedType)mySuperclass).getActualTypeArguments()[0];
13+
}
14+
15+
}

0 commit comments

Comments
 (0)