I have a generic class NetworkResponse<T>, t...
# android-architecture
o
I have a generic class NetworkResponse<T>, to wrap any network response:
Copy code
/**
 * 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:
Copy code
@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?
a
Response<Unit> works just fine as far as I know.
p
I think you want
Nothing?
. I’m a little confused by the question though, what do you mean by “T cannot be inferred”?