CONTENTS | PREV | NEXT | Java Object Serialization Specification version 6.0 |
CHAPTER 6 |
The stream format satisfies the following design goals:
A basic structure is needed to represent objects in a stream. Each attribute of the object needs to be represented: its classes, its fields, and data written and later read by class-specific methods. The representation of objects in the stream can be described with a grammar. There are special representations for null objects, new objects, classes, arrays, strings, and back references to any object already in the stream. Each object written to the stream is assigned a handle that is used to refer back to the object. Handles are assigned sequentially starting from 0x7E0000. The handles restart at 0x7E0000 when the stream is reset.A class object is represented by the following:
AnObjectStreamClass
object for a Class that is not a dynamic proxy class is represented by the following:
- A set of flags indicating various properties of the class, such as whether the class defines a
writeObject
method, and whether the class is serializable, externalizable, or an enum type- The number of serializable fields
- The array of fields of the class that are serialized by the default mechanismFor arrays and object fields, the type of the field is included as a string which must be in "field descriptor" format (e.g., "
Ljava/lang/Object;
") as specified in section 4.3.2 of The JavaTM Virtual Machine Specification, Second Edition.- Optional block-data records or objects written by the
annotateClass
method- The
ObjectStreamClass
of its supertype (null if the superclass is not serializable)
AnObjectStreamClass
object for a dynamic proxy class is represented by the following:
- The names of all of the interfaces implemented by the dynamic proxy class, listed in the order that they are returned by invoking the
getInterfaces
method on the Class object.- Optional block-data records or objects written by the
annotateProxyClass
method.- The ObjectStreamClass of its supertype,
java.lang.reflect.Proxy
.
The representation ofString
objects consists of length information followed by the contents of the string encoded in modified UTF-8. The modified UTF-8 encoding is the same as used in the JavaTM Virtual Machine and in thejava.io.DataInput
andDataOutput
interfaces; it differs from standard UTF-8 in the representation of supplementary characters and of the null character. The form of the length information depends on the length of the string in modified UTF-8 encoding. If the modified UTF-8 encoding of the givenString
is less than 65536 bytes in length, the length is written as 2 bytes representing an unsigned 16-bit integer. Starting with the JavaTM 2 platform, Standard Edition, v1.3, if the length of the string in modified UTF-8 encoding is 65536 bytes or more, the length is written in 8 bytes representing a signed 64-bit integer. The typecode preceding theString
in the serialization stream indicates which format was used to write theString
.Arrays are represented by the following:
Enum constants are represented by the following:
New objects in the stream are represented by the following: