Office Hours — Today, October 13

Yesterday, October 12

Mark M.
has entered the room
Oct 13
7:25 PM
Mark M.
turned on guest access
8:05 PM
chike m.
has entered the room
Mark M.
hello, chike!
how can I help you today?
chike m.
Hi Mark
I am fine
and you?
Mark M.
um, OK, I guess
chike m.
nice. Ok I want help with Retrofit
Mark M.
I can try -- what is the issue?
chike m.
my backend server sends two different JSON responses, that is the user object if successful and error message if failure
8:10 PM
chike m.
how can I handle that
since Retrofit allows just one
Mark M.
well, there are two issues: data types, and JSON parsers
the Retrofit code will be expecting a single return type
you would need to pick some common ancestor of your possible responses
that could be java.lang.Object, if needed
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
I am making educated guesses based on my knowledge of Retrofit
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":"..."}
in that case, you could model the response as a UserOrError object, with user and error fields
and then deal with one or the other being null
chike m.
I think that will be good
thanks Mark
Mark M.
you're welcome!
chike m.
has left the room
8:30 PM
Mark M.
turned off guest access

Yesterday, October 12

 

Office Hours

People in this transcript

  • chike mgbemena
  • Mark Murphy