Retrofit with RxJava and Gson

Pierce Zaifman
AndroidPub
Published in
1 min readJun 10, 2017

--

To get started you need to include the following in your build.gradle file:

Now you can set up your API interface with RxJava Observables, for example:

As you can see above, I can use my own data model and the JSON response will be converted automatically. I can also simply get a JsonObject if I just want to use the JSON myself.

Alternatively, I can set up my own deserializer, like so:

Lastly, here is my API creation with a deserializer for the User added in:

There are many different ways you can use Retrofit, RxJava, and Gson. This example can be used as a starting point, but there is much more you can do with each of these libraries if you need to.

If You Enjoyed Reading, Please Click That Little Heart. If You Want To Read More Like This, Follow Me On Medium. Thanks!

Originally published at piercezaifman.com on June 10, 2017.

--

--

Pierce Zaifman
AndroidPub

Freelance Android app developer | I love productivity, creativity, and finding balance | Email me for a quote at pierce@piercezaifman.com