Java - Deserialization InvalidClassException (No valid constructor)

后端 未结 3 1520
长发绾君心
长发绾君心 2021-02-19 02:33

I\'m trying to serialize an object and then deserialize it after sending its data to a client program.

Here\'s an example of how the object\'s inheritance works. The obj

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-19 03:16

    per this thread, they do not need to implement Serializable, but they (or at a minimum NPC because its the first non-serializable class in the heirarchy) must contain a 0-parameter constructor. if no constructors are defined in the classes, the implicit constructor is adaquate, but if you have other constructors defined in those classes, you must write an explicit 0-parameter constructor.

    Since you cannot control NPC, try creating child of it that defines an explicit 0-param constructor but that does not implement Serializable, and see if that doesn't do it.

提交回复
热议问题