retrofit returning valid json but pojo is empty

爷,独闯天下 提交于 2020-01-06 19:38:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!