Gson与改造相同的序列化名称

时间:2016-11-22 14:44:20

标签: java json gson retrofit

后端我使用一个Api'类型的'作为对象和另一个Api'类型'作为一个字符串,我使用电影,当我用Retrofit(Gson)解析它时,我得到错误。 我知道我需要写一个Desiralize,但我没有成功。

public class MovieResponse extends Movie {
    @SerializedName("media") @Expose public **String media**;
  }


public class Movie {
  @SerializedName("media")  **private Media media**;
  @SerializedName("id") @Expose private Integer id;
  @SerializedName("eventTypeId") @Expose private Integer eventTypeId;
  @SerializedName("typeName") @Expose private String typeName;
  @SerializedName("title") @Expose private String title;
  @SerializedName("englishTitle") @Expose private String englishTitle; ...

我的json回复:

{
  "query": "ab",
  "events": {
    "movies": [
      {
        "id": 2561599,
        "title": "bla",
        "englishTitle": null,
        "media": "http://images.com/w/a.jpg",
        "typeName": "movie",
        "eventTypeId": 178
      }
    ],
    "tvshows": [
      {
        "id": 1761630,
        "title": "a'",
        "englishTitle": "Ramat Aviv Gimel",
        "media": "http://c.jpg",
        "typeName": "tvshow",
        "eventTypeId": 166
      },
      {
        "id": 2855624,
        "title": "b",
        "englishTitle": "Lost in Africa",
        "media": "http://d.jpg",
        "typeName": "tvshow",
        "eventTypeId": 166
      }
    ]
  }
}

0 个答案:

没有答案