I work with a REST API that returns a JSON document that starts as follows and includes a โcollectionโ of elements with string identifiers of type โABCโ. Pay attention to the "routes" field, which contains a series of fields "ABC", "ABD", "ABE", etc. However, the routes are not presented as an array in json, so all of these
{ "status":true, "page":1, "per_page":500, "total_count":1234, "total_pages":8, "total_on_page":500, "routes":{ "ABC":[ { "value":22313, <......>
I use Retrofit, and the problem is that the route field is not an array (although conceptually this is true) and Retrofit / Gson require me to create a model object for routes with field vars abc, abd, etc. this is not practical as the data changes. For various reasons, changing the server API is difficult, so I'm looking for work on this Android client.
I believe these are the parameters:
Intercept the JSON document before it gets to Gson, and adjust the document, perhaps with a custom Gson parser or by intercepting an HTTP response.
Bypass JSON parsing and get a JSON document from Retrofit (I still have to figure out how to do this or if possible)
Use some Retrofit features. I do not know how to display field names in a collection.
I would appreciate help, especially if there is a quick and easy way to resolve this.
source share