问题
I am using retrofit to get a Json object from a server and I can get the Json (I see it completely and correct on the Log) but when I check the Object returned on the Callback it is empty which is weird.
I was having this problem returning an array of JSON Objects but I already tried with a single object and the same thing happens.
Here's the JSON:
{
"id" : "20176",
"name" : "Dave Attwood",
"dob" : "05/04/1987",
"position" : "Lock"
}
Here is the the Player class:
public class Player {
@SerializedName("id")
@Expose
private static String id;
@SerializedName("name")
@Expose
private static String name;
@SerializedName("dob")
@Expose
private static String dob;
@SerializedName("position")
@Expose
private static String position;
...getters and setters below
Here's the retrofit code:
@GET("/players/position/{position_name}")
void getPositionPlayers(@Path("position_name") String positionName,
Callback<Player> callback);
Here's the result from the GET Request where I get the JSON but then nothing in the Player Object:
@Subscribe
public void onLoadPlayers(final RequestPositionPlayersEvent event) {
mClientApi.getPositionPlayers(event.getmPlayerPosition(),
new Callback<Player>() {
@Override
public void success(Player players, Response response) {
mBus.post(new PlayersListEvent(players));
Log.i(TAG, "Success receiving PlayList");
}
@Override
public void failure(RetrofitError error) {
Log.i(TAG, "Failure receiving PlayList");
mBus.post(new ApiErrorEvent(error));
}
});
}
Anyone have any clue on what it might be? I've tried everything, I also have other projects working with a similar architecture and I can't find a difference for this one.
Thanks in advance for the help.
回答1:
Your variables are declared as static
. Remove the static
and it should work.
来源:https://stackoverflow.com/questions/26918648/retrofit-returning-valid-json-but-pojo-is-empty