ObjectStreamClass

public class ObjectStreamClass
extends Object implements Serializable

java.lang.Object
   ↳ java.io.ObjectStreamClass


Serialization's descriptor for classes. It contains the name and serialVersionUID of the class. The ObjectStreamClass for a specific class loaded in this Java VM can be found/created using the lookup method.

The algorithm to compute the SerialVersionUID is described in Object Serialization Specification, Section 4.6, Stream Unique Identifiers.

Summary

Fields

public static final ObjectStreamField[] NO_FIELDS

serialPersistentFields value indicating no serializable fields

Public methods

Class<?> forClass()

Return the class in the local VM that this version is mapped to.

ObjectStreamField getField(String name)

Get the field of this class by name.

ObjectStreamField[] getFields()

Return an array of the fields of this serializable class.

String getName()

Returns the name of the class described by this descriptor.

long getSerialVersionUID()

Return the serialVersionUID for this class.

static ObjectStreamClass lookup(Class<?> cl)

Find the descriptor for a class that can be serialized.

static ObjectStreamClass lookupAny(Class<?> cl)

Returns the descriptor for any class, regardless of whether it implements Serializable.

String toString()

Return a string describing this ObjectStreamClass.

Inherited methods

Fields

NO_FIELDS

Added in API level 1
public static final ObjectStreamField[] NO_FIELDS

serialPersistentFields value indicating no serializable fields

Public methods

forClass

Added in API level 1
public Class<?> forClass ()

Return the class in the local VM that this version is mapped to. Null is returned if there is no corresponding local class.

Returns
Class<?> the Class instance that this descriptor represents

getField

Added in API level 1
public ObjectStreamField getField (String name)

Get the field of this class by name.

Parameters
name String: the name of the data field to look for

Returns
ObjectStreamField The ObjectStreamField object of the named field or null if there is no such named field.

getFields

Added in API level 1
public ObjectStreamField[] getFields ()

Return an array of the fields of this serializable class.

Returns
ObjectStreamField[] an array containing an element for each persistent field of this class. Returns an array of length zero if there are no fields.

getName

Added in API level 1
public String getName ()

Returns the name of the class described by this descriptor. This method returns the name of the class in the format that is used by the Class#getName method.

Returns
String a string representing the name of the class

getSerialVersionUID

Added in API level 1
public long getSerialVersionUID ()

Return the serialVersionUID for this class. The serialVersionUID defines a set of classes all with the same name that have evolved from a common root class and agree to be serialized and deserialized using a common format. NonSerializable classes have a serialVersionUID of 0L.

Returns
long the SUID of the class described by this descriptor

lookup

Added in API level 1
public static ObjectStreamClass lookup (Class<?> cl)

Find the descriptor for a class that can be serialized. Creates an ObjectStreamClass instance if one does not exist yet for class. Null is returned if the specified class does not implement java.io.Serializable or java.io.Externalizable.

Parameters
cl Class: class for which to get the descriptor

Returns
ObjectStreamClass the class descriptor for the specified class

lookupAny

Added in API level 9
public static ObjectStreamClass lookupAny (Class<?> cl)

Returns the descriptor for any class, regardless of whether it implements Serializable.

Parameters
cl Class: class for which to get the descriptor

Returns
ObjectStreamClass the class descriptor for the specified class

toString

Added in API level 1
public String toString ()

Return a string describing this ObjectStreamClass.

Returns
String a string representation of the object.