I have a generic class NetworkResponse<T>, to wrap any network response:
/**
* 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?