I have an API response that is intended for general data return for various actions of our application. To make the application as versatile and flexible as possible, we set up an API to deliver a collection of URLs to use to create different strings in our actions. Our base object looks like this:
public class BaseApiObject { @SerializedName("apiVersion") private String apiVersion = null; @SerializedName("totalResults") private Integer totalResults = null; }
Our answer for the action is as follows:
public class ActivityApiResponse extends BaseApiObject { @SerializedName("results") private List<ScreenItem> results = new ArrayList<>(); }
And ScreenItem looks like this:
public class ScreenItem extends BaseApiObject { @SerializedName("apiUrls") private List<String> apiUrls = new ArrayList<>() ; }
I would like to do something like this with a modification:
@GET("{url}") Call<? extends BaseApiObject> getUrl(@Path("url") String url);
We know that every request we create will return a BaseApiObject, but we are not sure which type of object we will actually return - and some of these URLs will return a list of many different types of objects.
We get the following error:
java.lang.IllegalArgumentException: Method return type must not include a type variable or wildcard: retrofit2.Call<? extends com.company.BaseApiObject>
Is there any way with Retrofit to handle this scenario or do I need to return BaseApiObject and then use my own gson deserializer to actually return the correct type (s) of the object?
java android retrofit retrofit2
Scott
source share