my backend server sends two different JSON responses, that is the user object if successful and error message if failure
Oct 13
8:10 PM
chike m.
how can I handle that
chike m.
since Retrofit allows just one
Mark M.
well, there are two issues: data types, and JSON parsers
Mark M.
the Retrofit code will be expecting a single return type
Mark M.
you would need to pick some common ancestor of your possible responses
Mark M.
that could be java.lang.Object, if needed
Mark M.
but then you probably will need to create a custom converter factory to handle detecting what sort of JSON you got and routing Gson (or whatever) to parse it appropriately, returning the right actual value
chike m.
ok. Can I get a simple example of that please
Mark M.
sorry, I have never done that
Mark M.
I am making educated guesses based on my knowledge of Retrofit
Oct 13
8:15 PM
chike m.
ok
Mark M.
ideally, the JSON you got back would be something that wrapped either the user object or the error message
chike m.
yes
Mark M.
{"user": {...}} or {"error":"..."}
Mark M.
in that case, you could model the response as a UserOrError object, with user and error fields