Search code examples
androidjsonapiretrofitretrofit2

how to convert this JSON format into model class and get response into list using retrofit


    {
  "data": [
    {
      "resource": "teams",
      "id": 1,
      "name": "Pakistan",
      "code": "PAK",
      "image_path": "https://cdn.sportmonks.com/images/cricket/teams/1/1.png",
      "country_id": 190324,
      "national_team": true,
      "updated_at": "2018-11-29T11:47:20.000000Z"
    }
]
}

Solution

  • You can have something like this

    public class Response{
        private List<Data> data;
        // getter and setter
    }
    
    class Data{
        private String resource;
        private int id;
        private String name;
        private String code;
        @SerializedName("image_path")
        private String imagePath;
        @SerializedName("country_id")
        private long countryId;
        @SerializedName("national_team")
        private boolean nationalTeam;
        @SerializedName("updated_at")
        private String updatedAt;
    
        // getters and setters
    }