Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit with QueryMap

I have some request with the same endpoint but parameter and return type are different.

I used @QueryMap for the parameter but I don't know how to write the return type:

Must I write:

@GET("xxx")
Call<List<A1>> groupList1(@QueryMap Map<String, String> options);
@GET("xxx")
Call<List<A2>> groupList2(@QueryMap Map<String, String> options);
@GET("xxx")
Call<List<A3>> groupList3(@QueryMap Map<String, String> options);
....

or there is a shorter solution?

like image 860
user6123827 Avatar asked Jan 22 '26 19:01

user6123827


1 Answers

You can use JsonElement response type

 @GET("xxx")
    Call<JsonElement> groupList(@QueryMap Map<String, String> options);

Every call you will receive JsonElement which you can convert to JsonObject or JsonArray or even String. You can parse/deserealize it according to the your content

public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
      JsonElement jsonElement = response.body();
      //JsonArray array = jsonElement.getAsJsonArray();
      //JsonObject Obj = jsonElement .getAsJsonObject();
}
like image 193
kkost Avatar answered Jan 24 '26 10:01

kkost



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!