how to serialize class?

后端 未结 8 1935
自闭症患者
自闭症患者 2021-01-11 19:28

When I insert a List into mongodb, there is a problem:

Exception in thread \"main\" java.lang.IllegalArgumentException: can\'t serialize class mongodb.Person         


        
8条回答
  •  一向
    一向 (楼主)
    2021-01-11 20:11

    Just implement Serializable interface in Person class.

    Also it will be good to define a serialVersionUID in your class.

    AFAIK, while creating POJO class in java, the class should be serializable, if it is going to be transfered over some stream, have a default constructor, and allows access to properties/fields using getter and setter methods.

    You might be interested in reading this: Discover the secrets of the Java Serialization API

提交回复
热议问题