android – How to read a local json file using retrofit 2.0?


For API testing purposes, I need to read json files that would be my responses to API requests.

Well, with Retrofit 1.9 it was possible to implement a "Client" and override the "execute()" method so that it reads the json file locally.

With Retrofit 2.0, only OkHttpClient instances are accepted, and you can no longer make 'custom clients'.

What's the best way to get around this and make a mock for my Client and read the Json file locally?


OkHttp which was optional in version 1.9 is now required as well as automatically integrated. This brought several benefits to the library.

In this version, to parse Json, you need to declare Gson Converter dependency separately: compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'

Then use addConverterFactory . See example from the site itself:

Retrofit retrofit = new Retrofit.Builder()

        service = retrofit.create(APIService.class);

Scroll to Top