I'm trying to list a call from my server, but it comes empty. On postman I receive all the list, but I can't make it on android.
I have a Model Class :
public class Model {
@SerializedName("Title")
private String Title;
@SerializedName("Price")
private BigDecimal Price;
and the Call from my Interface :
@GET("api/Host/GetAllEvents")
Call<List<Model>> ListAllEvents();
My Service Class :
@Override
public void getAllEvents(onFinishedListener onFinishedListener) {
Call<List<Model>> call = retrofitEndpoint.ListAllEvents();
call.enqueue(new Callback<List<Model>>() {
@Override
public void onResponse(@NotNull Call<List<Model>> call, @NotNull Response<List<Model>> response) {
onFinishedListener.onFinished(response.body());
}
@Override
public void onFailure(@NotNull Call<List<Model>> call, @NotNull Throwable t) {
onFinishedListener.onError(t);
}
});
}
I receive the list size but with the properties null.
And my Retrofit client class :
private static final String BASE_URL = "http://192.168.0.101:3000";
private static Retrofit retrofit = null;
private static Gson gson = new GsonBuilder()
.create();
public static Retrofit getClient() {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(defaultClient())
.build();
}
return retrofit;
}
private static OkHttpClient defaultClient() {
return new OkHttpClient().newBuilder()
.connectTimeout(15, TimeUnit.SECONDS).
readTimeout(15, TimeUnit.SECONDS).
writeTimeout(15, TimeUnit.SECONDS).
addInterceptor(chain -> {
Request newRequest = chain.request().newBuilder()
.addHeader("Authorization", "Bearer " + Hawk.get("t"))
.build();
return chain.proceed(newRequest);
}).build();
}