Reputation: 35
I'm trying to get a list of players. I receive the response of Call > 3 Players but in a bizzare format. I do not know where is my mistake, I search for 5 hours without result.
ApiClient.class:
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sat.sat.Method.FMethod;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
/**
* Created by Haytham on 2018-05-15.
*/
public class ApiClient {
public static final String Base_Url = "https://www.url.com/";
public static Retrofit getRetrofit() {
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
.create();
Retrofit retrofit = new Retrofit
.Builder()
.baseUrl(Base_Url)
.addConverterFactory(GsonConverterFactory.create(gson)).build();
return retrofit;
}}
Interface:
@GET("api/coach/player_list")
Call<List<PlayerListResponse>> getPlayerList (@Query("token") String Token);
MyActivity:
***ApiInterface service = ApiClient.getRetrofit().create(ApiInterface.class);
Call <List<PlayerListResponse>> PlayerListCall = service.getPlayerList(FMethod.TokenFC);
PlayerListCall.enqueue(new Callback<List<PlayerListResponse>>() {
@Override
public void onResponse(Call<List<PlayerListResponse>> call, Response<List<PlayerListResponse>> response) {
int StatusCode=response.code();
if (StatusCode==200) {
Log.d("PlayerList", "onResponse: "+StatusCode+ response.body().toString());
}
if (StatusCode==401) {
Toast.makeText(Coach_list_player.this, "Token"+FMethod.TokenFC, Toast.LENGTH_SHORT).show();
}
}***
My POJO :
package com.sweatacademytech.sweatacademy.Pojo;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class PlayerListResponse {
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("fname")
@Expose
private String fname;
@SerializedName("lname")
@Expose
private String lname;
@SerializedName("email")
@Expose
private String email;
@SerializedName("date_assigned")
@Expose
private String dateAssigned;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getDateAssigned() {
return dateAssigned;
}
public void setDateAssigned(String dateAssigned) {
this.dateAssigned = dateAssigned;
}
}
And i found in my log.debug: 06-17 16:57:23.007 200 It's Okey [com.sat.sweatacademy.Pojo.PlayerListResponse@2077dfd, com.sat.sat.Pojo.PlayerListResponse@441eaf2, com.sat.sat.Pojo.PlayerListResponse@ed2f543]
Upvotes: 0
Views: 293
Reputation: 3535
There is no error
Call<List<PlayerListResponse>> getPlayerList (@Query("token") String Token);
Your method return a List
of PlayerList
... and log showed exactly this...
com.sweatacademytech.sweatacademy.Pojo.PlayerListResponse
If you are worried because you didn't see the actual Players fields at log is because you didn't override toString()
but this is not an error, is just misinterpretation of you...
by the way you should name better your classes
Upvotes: 2