Retrofit with QueryMap

Deadly 提交于 2019-12-10 18:35:31

问题


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?


回答1:


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();
}


来源:https://stackoverflow.com/questions/37766953/retrofit-with-querymap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!