NotSerializableException on SimpleListProperty

后端 未结 6 1892
予麋鹿
予麋鹿 2020-12-10 08:09

I\'m using Javafx, and I wrap my objects into ListProperty to let the tableview updates for any changes on the objects of the list. Now I\'m trying to serialize my project a

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-10 09:06

    The property Object needs to implement the Serializable interface. Here is a simple extension of SimpleObjectProperty, for generic objects, that is serializable:

    public class WriteableObjectProperty extends SimpleObjectProperty implements Serializable {
    
        public WriteableObjectProperty () {
            super();
        }
    
        public WriteableObjectProperty (T obj) {
            super(obj);
        }
    
    
        private void writeObject (ObjectOutputStream s) throws IOException {
            s.defaultWriteObject();
            s.writeObject(get());
        }
    
        private void readObject (ObjectInputStream s) throws IOException, ClassNotFoundException {
            s.defaultReadObject();
            set((T) s.readObject());
        }
    }
    

提交回复
热议问题