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 hereObjectOutputStream
writes the value returned by the enum constant'sname
method. To deserialize an enum constant,ObjectInputStream
reads the constant name from the stream; the deserialized constant is then obtained by calling thejava.lang.Enum.valueOf
method, 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
, andreadResolve
methods defined by enum types are ignored during serialization and deserialization. Similarly, anyserialPersistentFields
orserialVersionUID
field declarations are also ignored--all enum types have a fixedserialVersionUID
of0L
. 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:
Posts (Atom)