How to handle dynamic JSON response with Retrofit

Note: This post is based on the widely used Retrofit2 networking library. Although the examples use a Gson converter, the same concept can be used with most of the other supported ones as well.

Imagine you’re in a situation where your backend can return a JSON response that’s dynamic in nature, a.k.a some parts of it don’t adhere to a specific pre-defined schema. Say you retrieve information about a webpage that you need to open in a WebView. You need to support both GET and POST HTTP requests, so two valid responses are:
read more