I have REST api which respond according to current state at the same path. Let's assume /api/users
response with
{
"status":200,
"error":false,
"users":["a","b"]
}
if user is authorised.
Else if user is not authorised it respond with {"status":403,"error":true,"redirect":"url"}
. When defining Interface for api calls with Retrofit it needs the exact type of response object.
Ex:
@GET("users")
Call<List<User>> getUsers()
But here API server respond with different shapes of object. How to handle this type of situation?
Opinion based answer
A Base class
A success response class
A failure response class
API interface
When data arrives
use this class as your model pojo
}
and call this model in your retrofit as...