Top Description Fields Constructors Methods
java.io

public Class ObjectStreamField

extends Object
implements Comparable<Object>
Class Inheritance
All Implemented Interfaces
java.lang.Comparable
Imports
java.lang.reflect.Field, jdk.internal.reflect.CallerSensitive, .Reflection, sun.reflect.misc.ReflectUtil

A description of a Serializable field from a Serializable class. An array of ObjectStreamFields is used to declare the Serializable fields of a class.
Authors
Mike Warres, Roger Riggs
Since
1.2
See Also
ObjectStreamClass

Field Summary

Modifier and TypeField and Description
private final Field
field

corresponding reflective field object, if any

private final String
name

field name

private int
offset

offset of field value in enclosing field group

private final String
signature

canonical JVM signature of field type, if given

private final Class<?>
type

field type (Object.class if unknown non-primitive type)

private String
typeSignature

lazily constructed signature for the type, if no explicit signature

private final boolean
unshared

whether or not to (de)serialize field values as unshared

Constructor Summary

AccessConstructor and Description
public
ObjectStreamField(String
the name of the serializable field
name
,
Class<?>
the Class object of the serializable field
type
)

Create a Serializable field with the specified type.

public
ObjectStreamField(String
field name
name
,
Class<?>
field type
type
,
boolean
if false, write/read field values in the same manner as writeObject/readObject; if true, write/read in the same manner as writeUnshared/readUnshared
unshared
)

Creates an ObjectStreamField representing a serializable field with the given name and type.

pack-priv
ObjectStreamField(String name, String signature, boolean unshared)

Creates an ObjectStreamField representing a field with the given name, signature and unshared setting.

pack-priv
ObjectStreamField(Field field, boolean unshared, boolean showType)

Creates an ObjectStreamField representing the given field with the specified unshared setting.

Method Summary

Modifier and TypeMethod and Description
public int
compareTo(Object
the object to be compared.
obj
)

Implements java.lang.Comparable.compareTo.

Compare this field with another ObjectStreamField.

pack-priv Field
getField()

Returns field represented by this ObjectStreamField, or null if ObjectStreamField is not associated with an actual field.

public String

Returns:

a String representing the name of the serializable field
getName
()

Get the name of this field.

public int

Returns:

the offset of this field
getOffset
()

Offset of field within instance data.

pack-priv String
getSignature()

Returns JVM type signature of field (similar to getTypeString, except that signature strings are returned for primitive fields as well).

public Class<?>

Returns:

a Class object representing the type of the serializable field
getType
()

Get the type of the field.

public char

Returns:

the typecode of the serializable field
getTypeCode
()

Returns character encoding of field type.

public String

Returns:

null if this field has a primitive type.
getTypeString
()

Return the JVM type signature.

public boolean

Returns:

true if and only if this field corresponds to a primitive type
isPrimitive
()

Return true if this field has a primitive type.

public boolean

Returns:

true if this field is unshared
isUnshared
()

Returns boolean value indicating whether or not the serializable field represented by this ObjectStreamField instance is unshared.

protected void
setOffset(int
the offset of the field
offset
)

Offset within instance data.

public String
toString()

Overrides java.lang.Object.toString.

Return a string that describes this field.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

fieldback to summary
private final Field field

corresponding reflective field object, if any

nameback to summary
private final String name

field name

offsetback to summary
private int offset

offset of field value in enclosing field group

signatureback to summary
private final String signature

canonical JVM signature of field type, if given

typeback to summary
private final Class<?> type

field type (Object.class if unknown non-primitive type)

typeSignatureback to summary
private String typeSignature

lazily constructed signature for the type, if no explicit signature

unsharedback to summary
private final boolean unshared

whether or not to (de)serialize field values as unshared

Constructor Detail

ObjectStreamFieldback to summary
public ObjectStreamField(String name, Class<?> type)

Create a Serializable field with the specified type. This field should be documented with a serialField tag.

Parameters
name:String

the name of the serializable field

type:Class<?>

the Class object of the serializable field

ObjectStreamFieldback to summary
public ObjectStreamField(String name, Class<?> type, boolean unshared)

Creates an ObjectStreamField representing a serializable field with the given name and type. If unshared is false, values of the represented field are serialized and deserialized in the default manner--if the field is non-primitive, object values are serialized and deserialized as if they had been written and read by calls to writeObject and readObject. If unshared is true, values of the represented field are serialized and deserialized as if they had been written and read by calls to writeUnshared and readUnshared.

Parameters
name:String

field name

type:Class<?>

field type

unshared:boolean

if false, write/read field values in the same manner as writeObject/readObject; if true, write/read in the same manner as writeUnshared/readUnshared

Since
1.4
ObjectStreamFieldback to summary
pack-priv ObjectStreamField(String name, String signature, boolean unshared)

Creates an ObjectStreamField representing a field with the given name, signature and unshared setting.

ObjectStreamFieldback to summary
pack-priv ObjectStreamField(Field field, boolean unshared, boolean showType)

Creates an ObjectStreamField representing the given field with the specified unshared setting. For compatibility with the behavior of earlier serialization implementations, a "showType" parameter is necessary to govern whether or not a getType() call on this ObjectStreamField (if non-primitive) will return Object.class (as opposed to a more specific reference type).

Method Detail

compareToback to summary
public int compareTo(Object obj)

Implements java.lang.Comparable.compareTo.

Compare this field with another ObjectStreamField. Return -1 if this is smaller, 0 if equal, 1 if greater. Types that are primitives are "smaller" than object types. If equal, the field names are compared.

Parameters
obj:Object

Doc from java.lang.Comparable.compareTo.

the object to be compared.

Returns:int

Doc from java.lang.Comparable.compareTo.

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

getFieldback to summary
pack-priv Field getField()

Returns field represented by this ObjectStreamField, or null if ObjectStreamField is not associated with an actual field.

getNameback to summary
public String getName()

Get the name of this field.

Returns:String

a String representing the name of the serializable field

getOffsetback to summary
public int getOffset()

Offset of field within instance data.

Returns:int

the offset of this field

See Also
setOffset
getSignatureback to summary
pack-priv String getSignature()

Returns JVM type signature of field (similar to getTypeString, except that signature strings are returned for primitive fields as well).

getTypeback to summary
public Class<?> getType()

Get the type of the field. If the type is non-primitive and this ObjectStreamField was obtained from a deserialized ObjectStreamClass instance, then Object.class is returned. Otherwise, the Class object for the type of the field is returned.

Returns:Class<?>

a Class object representing the type of the serializable field

Annotations
@SuppressWarnings:removal
@CallerSensitive
getTypeCodeback to summary
public char getTypeCode()

Returns character encoding of field type. The encoding is as follows:

B            byte
C            char
D            double
F            float
I            int
J            long
L            class or interface
S            short
Z            boolean
[            array
Returns:char

the typecode of the serializable field

getTypeStringback to summary
public String getTypeString()

Return the JVM type signature.

Returns:String

null if this field has a primitive type.

isPrimitiveback to summary
public boolean isPrimitive()

Return true if this field has a primitive type.

Returns:boolean

true if and only if this field corresponds to a primitive type

isUnsharedback to summary
public boolean isUnshared()

Returns boolean value indicating whether or not the serializable field represented by this ObjectStreamField instance is unshared.

Returns:boolean

true if this field is unshared

Since
1.4
setOffsetback to summary
protected void setOffset(int offset)

Offset within instance data.

Parameters
offset:int

the offset of the field

See Also
getOffset
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return a string that describes this field.

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object