简体   繁体   中英

Java - Default Serialization of Objects

The default serialization mechanism for an object writes the class of the object, the class signature, and the values of all non-transient and non-static fields

  1. Is there any difference between "Class of the Object" and "Class Signature" here?
  2. Since "Class Signature" and the "Class" also passed, Does JVM loads the default class on the target system? (or) the class which is passed in the serialized object?

The phrase "writes the class of the object" really means "writes the class name of the object". java object serialization does not write the class bytes, only the name of the class. when the object is deserialized later, it will use the class bytes defined in the current jvm.

You do not store some kind of serialised class definition, just the contents of the instance that you serialised. When deserialising, the JVM will use the class definition that it finds in its classpath.

So you do have to understand how versionning works ...

I believe "class signature" is supposed to refer to the class' (and serialisable superclass') field names and types, and the serial version UID.

By default, ObjectInputStream looks up the class name in the "latest" class loader (that is the non-bootstrap class loader closest on the call stack). Sensible subclasses lookup using a specified class loader. RMI, by default (switch it off with a system property), finds the location (URL) to load new classes from an annotation embedded in the stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM