可打包始终通过NOT NULL检查

时间:2019-02-13 13:37:40

标签: java android parcelable

我在另一个Parcelable对象中拥有的Parcelable对象总是通过Not Null检查,即使响应是api响应中的null“ {}”。

这是我嵌套的可包裹对象:

public class PilotBean implements Parcelable {
    @SerializedName("pilot_tag_url")
    private String pilotTagUrl;

    @SerializedName("pilot_type")
    private String pilotType;

    @SerializedName("pilot_viewed_call")
    private String pilotViewedCall;

    @SerializedName("time_between_units")
    private int timeBetweenUnits;

    public String getPilotTagUrl() {
        return pilotTagUrl;
    }

    public String getPilotType() {
        return pilotType;
    }

    public String getPilotViewedCall() {
        return pilotViewedCall;
    }

    public int getTimeBetweenUnits() {
        return timeBetweenUnits;
    }

    public static Creator<PilotBean> getCREATOR() {
        return CREATOR;
    }

    protected PilotBean(Parcel in) {
        pilotTagUrl = in.readString();
        pilotType = in.readString();
        pilotViewedCall = in.readString();
        timeBetweenUnits = in.readInt();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeValue(pilotTagUrl);
        dest.writeValue(pilotType);
        dest.writeValue(pilotViewedCall);
        dest.writeValue(timeBetweenUnits);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<PilotBean> CREATOR = new Creator<PilotBean>() {
        @Override
        public PilotBean createFromParcel(Parcel in) {
            return new PilotBean(in);
        }

        @Override
        public PilotBean[] newArray(int size) {
            return new PilotBean[size];
        }
    };
}


if (episodeBean.getPilot() != null) {
    //MY CODE
}

当我检查此对象是否为!= null时,它始终返回true。即使对象的响应为空的“ {}”。

是否有解决此问题的方法或如何正确检查可包裹物体的!= null?

0 个答案:

没有答案