I have a server where I query to get a list of topics in a forum. The data returned via curl is something like this -
[
{
"id": 728,
"date": "2016-01-01T13:01:51",
"date_gmt": "2016-01-01T07:31:51",
....
},
{
"id": 556,
"date": "2015-06-07T21:16:59",
"date_gmt": "2015-06-07T15:46:59",
....
},
{
"id": 554,
"date": "2015-06-07T21:16:28",
"date_gmt": "2015-06-07T15:46:28",
....
}
]
Here every JSONObject is a data about forum topic.
{
"id": 554,
"date": "2015-06-07T21:16:28",
"date_gmt": "2015-06-07T15:46:28",
....
}
I want to display this data in a ListView in an Android app.
However, since I am using retrofit2 and gson to create the objects for the ListView, the response I always get is Not Found.
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(ENDPOINT)
.addConverterFactory(buildGsonConverter())
.build();
serverAPI = retrofit.create(ServerAPI.class);
private Converter.Factory buildGsonConverter() {
return GsonConverterFactory.create();
}
Call<List<Forum>> call = App.serverAPI.getListOfForums();
call.enqueue(new Callback<List<Forum>>() {
@Override
public void onResponse(Call<List<Forum>> call, Response<List<Forum>> response) {
Log.i(TAG, "onResponse: " + (null != response.message() ? response.message() : ""));
Log.i(TAG, "response body - " + (null != response.body() ? response.body() : ""));
if (response.isSuccessful()) {
adapter.setForums(response.body());
adapter.notifyDataSetChanged();
}
}
@Override
public void onFailure(Call<List<Forum>> call, Throwable t) {
Log.i(TAG, "onFailure: " + t.toString());
Log.i(TAG, "onFailure: " + t.getMessage());
}
});
ServerAPI.class -
@GET("/forum/")
Call<List<Forum>> getListOfForums();
Right now I am not doing anything when deserializing the returned JSON. Even if I use a JsonDeserializer, how should I go about it such that it is easier to populate the List<Forum>.