Tuesday, 24 February 2015
Serialization of Enum in java
Enum constants are serialized differently than ordinary serializable or externalizable objects. The serialized form of an enum constant consists solely of its name; field values of the constant are not present in the form. To serialize an enum constant,Main ariticle can be found in click hereObjectOutputStreamwrites the value returned by the enum constant'snamemethod. To deserialize an enum constant,ObjectInputStreamreads the constant name from the stream; the deserialized constant is then obtained by calling thejava.lang.Enum.valueOfmethod, passing the constant's enum type along with the received constant name as arguments. Like other serializable or externalizable objects, enum constants can function as the targets of back references appearing subsequently in the serialization stream.The process by which enum constants are serialized cannot be customized: any class-specificwriteObject,readObject,readObjectNoData,writeReplace, andreadResolvemethods defined by enum types are ignored during serialization and deserialization. Similarly, anyserialPersistentFieldsorserialVersionUIDfield declarations are also ignored--all enum types have a fixedserialVersionUIDof0L. Documenting serializable fields and data for enum types is unnecessary, since there is no variation in the type of data sent.
other resource
Subscribe to:
Comments (Atom)