简体   繁体   English

Java - 对象的默认序列化

[英]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? 由于“Class Signature”和“Class”也已通过,JVM是否在目标系统上加载默认类? (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. java对象序列化不写类字节,只写类的名称。 when the object is deserialized later, it will use the class bytes defined in the current jvm. 当对象在以后反序列化时,它将使用当前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. 反序列化时,JVM将使用它在类路径中找到的类定义。

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. 我相信“类签名”应该引用类'(和serialisable superclass')字段名称和类型,以及串行版本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). 默认情况下, ObjectInputStream在“最新”类加载器(即最靠近调用堆栈的非引导类加载器)中查找类名。 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. 默认情况下,RMI(使用系统属性将其关闭)查找从流中嵌入的注释加载新类的位置(URL)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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