我的模型看起来像这样简化
@Table
public class Movie extends SugarRecord implements Parcelable {
@SerializedName("id")
@Expose
private Long movieId;
@SerializedName("adult")
@Expose
private Boolean adult;
@SerializedName("backdrop_path")
@Expose
private String backdropPath;
@SerializedName("genre_ids")
@Expose
private List<Integer> genreIds = new ArrayList<>();
@SerializedName("original_language")
@Expose
private String originalLanguage;
@SerializedName("original_title")
@Expose
private String originalTitle;
@SerializedName("overview")
@Expose
private String overview;
@SerializedName("release_date")
@Expose
private String releaseDate;
@SerializedName("poster_path")
@Expose
private String posterPath;
@SerializedName("popularity")
@Expose
private Double popularity;
@SerializedName("title")
@Expose
private String title;
@SerializedName("video")
@Expose
private Boolean video;
@SerializedName("vote_average")
@Expose
private Double voteAverage;
@SerializedName("vote_count")
@Expose
private Integer voteCount;
private Boolean favourite;
public Movie() {
this.favourite = false;
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Movie createFromParcel(Parcel in) {
return new Movie(in);
}
public Movie[] newArray(int size) {
return new Movie[size];
}
};
public Movie(Parcel in) {
this.adult = in.readByte() != 0;
this.movieId = in.readLong();
this.backdropPath = in.readString();
in.readList(this.genreIds, null);
this.originalLanguage = in.readString();
this.originalTitle = in.readString();
this.overview = in.readString();
this.releaseDate = in.readString();
this.posterPath = in.readString();
this.popularity = in.readDouble();
this.title = in.readString();
this.video = in.readByte() != 0;
this.voteAverage = in.readDouble();
this.voteCount = in.readInt();
this.favourite = in.readByte() != 0;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (this.adult ? 1 : 0));
dest.writeLong(this.movieId);
dest.writeString(this.backdropPath);
dest.writeList(this.genreIds);
dest.writeString(this.originalLanguage);
dest.writeString(this.originalTitle);
dest.writeString(this.overview);
dest.writeString(this.releaseDate);
dest.writeString(this.posterPath);
dest.writeDouble(this.popularity);
dest.writeString(this.title);
dest.writeByte((byte) (this.video ? 1 : 0));
dest.writeDouble(this.voteAverage);
dest.writeInt(this.voteCount);
dest.writeByte((byte) (this.favourite ? 1 : 0));
}
}
当 Gson 尝试转换从改造收到的结果时,我收到错误消息。
java.lang.IllegalArgumentException: class Movie declares multiple JSON fields named id
当 Movie 不扩展 SugarRecord 时,它工作得非常好。
我可以在这里做什么?