<font class="popmake-631">Subscribe</font>Subscribe with Androidlift to get new post on mail.

Android OKHttp library with gson parsing for network data operations

Most apps needs network connections to external services to access and exchange data, although this is through REST APIs and an HTTP client in your app. OKHttp is an Android HTTP client library from Square that reduces the steps needed and means you can spend more time on the important areas of your app.

Why OkHttp?

  • HTTP/2 support allows all requests to the same host to share a socket.
  • Connection pooling reduces request latency (if HTTP/2 isn’t available).
  • Transparent GZIP shrinks download sizes.
  • Response caching avoids the network completely for repeat requests.
  • supports Android 2.3 and above, which is more than 99% of the market based on current statistics of version usage.


Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object. Gson can work with arbitrary Java objects including pre-existing objects that you do not have source-code of.

Gson Goals

  • It Provide simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa.
  • Allow pre-existing unmodifiable objects to be converted to and from JSON
  • Extensive support of Java Generics
  • Event allow custom representations for objects
  • Support arbitrarily complex objects (with deep inheritance hierarchies and extensive use of generic types)

To build model classes of directly just add the GsonFormat plugin

  1. Install GsonFormat plugin
  2. Generate a new class.
  3. Inside the body of the class, right click.
  4. Inside the menu that opens choose Generate.
  5. In the new menu that open choose Gson-Format.

Add Dependencies

Okhttp :


Gson :







App build.gradle

Output : –