如何使用构造函数中的自定义对象使我的自定义模型可打包

How to make my Custom Model Parcelable with custom object in it's Constructor

这是我的 class,我正在尝试使其可打包,正如您在代码中看到的那样,我卡在代码中的某些地方:

public class CommentModel implements Parcelable{

    String      COMMENT_CONTENT;
    String      COMMENT_ID;
    UserModel   COMMENT_ACTOR;

    public CommentModel(String comment_content, String comment_id, UserModel comment_user){

        this.COMMENT_CONTENT    = comment_content;
        this.COMMENT_ID         = comment_id;
        this.COMMENT_ACTOR      = comment_user;

    }

    /*== constructor to rebuild object from the Parcel ==*/
    public CommentModel(Parcel source) {

        this.COMMENT_CONTENT                = source.readString();
        this.COMMENT_ID                     = source.readString();

        // This is where I'm stuck!
        this.COMMENT_ACTOR                  = source............;
    }

    public String getContent(){
        return this.COMMENT_CONTENT;
    }

    public void setContent(String content){
        this.COMMENT_CONTENT    = content;
    }

    public String getId(){
        return this.COMMENT_ID;
    }

    public void setId(String id){
        this.COMMENT_ID = id;
    }

    public UserModel getActor(){
        return this.COMMENT_ACTOR;
    }

    public void setActor(UserModel actor){
        this.COMMENT_ACTOR  = actor;
    }

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

    @Override
    public void writeToParcel(Parcel dest, int flags) {

        dest.writeString(COMMENT_CONTENT);
        dest.writeString(COMMENT_ID);

        // This is where I'm stuck too! :(
        dest.write.....
    }

    public static final Parcelable.Creator<CommentModel> CREATOR = new Creator<CommentModel>() {

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

        @Override
        public CommentModel createFromParcel(Parcel source) {
            return new CommentModel(source);
        }
    };


}

应该怎么做呢? 完全可能吗?如果不是如何处理这个问题?

P.s: 我的 UserModel() 当然也是 Parcelable。

如果UserModelParcelable,可以用writeParcelable to write the object and readParcelable读回来。例如

dest.writeParcelable(COMMENT_ACTOR, flages);

写,

COMMENT_ACTOR = source.readParcelable(UserModel.class.getClassLoader());

回读。