Home  >  Q&A  >  body text

java - fastjson 与 serialVersionUID 如何建立关系?

如果使用 fastjson 作为序列化方法,那么即使类实现了 Serializable 接口,其中的 serialVersionUID 似乎也没什么用。

怎么能让 serialVersionUID 起作用,用来防止将内容反序列化的时候类型不符。

伊谢尔伦伊谢尔伦2717 days ago801

reply all(3)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 13:58:38

    Serializable is used for ObjectInput(Output)Stream. Objects that implement this interface will have one.
    Constant for serialVersionUID.
    The sequence of fastJson "turns" an object into a json file. If the Serializable interface is implemented, there will be a serialVersionUID attribute.
    You can save the serialVersionUID value of the current object during serialization. When deserializing the conversation, check whether it is equal to the last saved value. At this time, you can judge whether they are the same object.
    ——————Java newbie, please don’t spray lightly

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:58:38

    No special configuration is required for fastjson serialization and deserialization. The only requirement is that the class you serialize conforms to the Java bean specification.

    https://github.com/alibaba/fastjson/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E...

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 13:58:38

    If the object equals method is not overridden, the comparison result is not equal, and the comparison is the memory address.

    reply
    0
  • Cancelreply