Retrofit with RxJava and Gson

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.

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

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store