I have to work with an API which using JSend format.
Long story short it is using HTTP status codes which indicates status like:
- 200 is Success
- 406 is Unauthorized
Which is good because I can determine from this whether my API request is succeed or not.
BUT:
As JSend format has it's own thing, it has ALSO have a little status indicator at response just like this:
{
status : "success",
data : { "post" : { "id" : 2, "title" : "Another blog post", "body" : "More content" }}
}
So it has a 'status' field which ALSO shows whether the API request is succeed or not.
PROBLEM:
Retrofit made to parse the response to POJO so it assumes that the responses contains ONLY the Model and no indicators for success, just like this for example: (A post Model instance)
{ "id" : 2, "title" : "Another blog post", "body" : "More content" }
My question is:
Is there a solution for this? Can I pre-parse the status indicators, split the 'data' (Model) part of the response and give it to retrofit for parse only that part?
If not I would have to add a "status" attribute to each of my models which is clearly not a walkable way, I won't do that.
Should I just stick with manual parsing and use ResponseBody
instead of my Models at
void onResponse(Call<T> call, Response<T> response);
for T
type paramter?
Because in that way I can use .string()
and convert the string to JSON and after that I can parse my Models manually like writing the parser for them.
I would really like to use Retrofit's feature for automatic parsing because with JSend I just cannot imagine how could be this properly done if anyhow at all.
I cannot change the API it's going to be this way.