Ofir Bar
02/12/2020, 6:13 PM/**
* A class wrapping every network response
*/
data class NetworkResponse<T>(@SerializedName("code") val code: Int,
@SerializedName("message") val message: String,
@SerializedName("data") val data: T)
However, I know, for sure, that whenever making a network request to our backend, some network responses will send back a NetworkResponse
with data
equals null
. So then T
cannot be inferred.
For example, when we Patch a User data, I receive code 200 OK, but data
object returned is null (no data returned back is expected).
Here is the network request using retrofit:
@PATCH("user")
suspend fun updateUserBasicDetails(@Body basicDetailsBasicDetailsRequest: UserBasicDetailsRequest) : NetworkResponse<WHAT_TO_DO_HERE?>
I am not sure what type to set for NetworkRequest in this case. I need to give some object to the NetworkResponse, but don’t want to just put something ugly and unrelated like “String?“.
What can be done?aipok
02/12/2020, 7:23 PMpt
02/12/2020, 7:24 PMNothing?
. I’m a little confused by the question though, what do you mean by “T cannot be inferred”?