Can you please tell me how to specify the json file from the assests folder for Retrofit? Now my json file is taken from a remote site

SiteController

public class SiteController { private static final String BASE_URL = "https://site.ru"; private static Retrofit getRetrofirInstance() { return new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).build(); } public static SiteAPI getSiteAPI() { return getRetrofirInstance().create(SiteAPI.class); } } 

Interface siteapi

 public interface SiteAPI { @GET("/for_android/info.json") Call<ItemList> getInfo(); } 

    1 answer 1

    The Retrofit library is used for network requests. It does not need to read local data. All you need is the json Gson parser.

    We read the file from assets and parse it into an object using Gson:

     try { InputStream json = getAssets().open("content.json"); ItemList itemList = new Gson() .fromJson(new InputStreamReader(json, "UTF-8"), ItemList.class); } catch (IOException e) { e.printStackTrace(); }