I was looking for a simple example about how to implement a custom converter for Retrofit 2. Unfortunately found none.
I found this example but, at least for me, it’s too complicated for my purpose.
Happilly, I found a solution.
This solution is to use GSON deserializers
.
We don’t need to create a custom converter, we just have to customize the GSON converter
.
Here is a great tutorial. And here is the code I used to parse the JSON described in my question:
-
Login Deserializer: Defines how to parse the JSON as an object of our target class (using conditionals and whatever we need).
-
Custom GSON converter: Builds a GSON converter that uses our custom deserializer.