Can retrofit support template well? #3529
markwang1971
started this conversation in
General
Replies: 1 comment 3 replies
-
|
There is no way to access the real value of T which is erased to Object by the compiler. This is why Gson is returning a map (or a list or a scalar), it has no type information. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
interface GetRadioListApi {
@get(SUB_URL)
suspend fun getRadioList(@QueryMap queryMap: BaseRequest): RadioListResponse
data class RadioListResponse(val msg: String, val ret: Int, val sub_ret: Int)
}
publicRadioListApi.getRadioList(params) does work well.
But the following does not work.
interface GetRadioListApi {
@get(SUB_URL)
suspend fun < T > getRadioList(@QueryMap queryMap: BaseRequest): T
data class RadioListResponse(val msg: String, val ret: Int, val sub_ret: Int)
}
The compiling is no any problem. But publicRadioListApi.getRadioList<GetRadioListApi.RadioListResponse>(params) always returns "Network error: java.lang.ClassCastException: com.google.gson.internal.LinkedTreeMap cannot be cast to com.bmwgroup.apinext.music.backend.webapi.radio.GetRadioListApi$RadioGroup"
Is it a valid case?
Beta Was this translation helpful? Give feedback.
All reactions