mcharmas/android-parcelable-intellij-plugin

How to parcel private List<T> data;

Opened this issue · 1 comments

i have code private List<T> data; , and i got problem on Parcel in, have idea ?

@SerializedName("message")
    private String message;
    @SerializedName("data")
    private List<T> data;

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public ResponseListService() {
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.message);
        dest.writeList(this.data);
    }

    protected ResponseListService(Parcel in) {
        this.message = in.readString();
        this.data = new ArrayList<T>();
        in.readList(this.data, T.class.getClassLoader());
    }

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

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

Hi,
it's impossible to get T.class.getClassLoader() in java from type param. I am not sure if this is going to work but you may try to pass different classloader.

Here someone is hacking the reality and trying to accomplish what you are trying to do: https://stackoverflow.com/questions/18797399/is-it-possible-to-parcel-a-generic-class

The plugin doesn't support it and probably never will.