serialization/deserialization mechanism

后端 未结 5 960
粉色の甜心
粉色の甜心 2021-01-13 04:42

Say, I have a class X which has a field value, that is,

class X implements Serializable {
    private i         


        
5条回答
  •  清歌不尽
    2021-01-13 05:30

    Some good links The Java serialization algorithm revealed

    1) does deserialization fail in case the access specifier of the field changes OR some or all of the methods go missing in the class at the deserialization end ?

    Serialization happens using Using Reflection

    Java Detects the changes to a class using the

    private static final long serialVersionUID

    The default involves a hashcode. Serialization creates a single hashcode, of type long, from the following information:

    • The class name and modifiers

    • The names of any interfaces the class implements

    • Descriptions of all methods and constructors except private methods and constructors

    • Descriptions of all fields except private, static, and private transient

    The default behavior for the serialization mechanism is a classic "better safe than sorry" strategy. The serialization mechanism uses the suid, which defaults to an extremely sensitive index, to tell when a class has changed. If so, the serialization mechanism refuses to create instances of the new class using data that was serialized with the old classes.

    2) what is the mechanism by which fields are assigned their values during deserialization ?

提交回复
热议问题