Class SerializableField


  • public final class SerializableField
    extends Object
    Reflection information about a field on a serializable class.
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean getBoolean​(Object instance)
      Get the boolean value of this field on the given object instance.
      byte getByte​(Object instance)
      Get the byte value of this field on the given object instance.
      char getChar​(Object instance)
      Get the char value of this field on the given object instance.
      double getDouble​(Object instance)
      Get the double value of this field on the given object instance.
      Field getField()
      Deprecated.
      As of Java 9, accessible fields are generally disallowed; use the #setXXX(Object,value) methods instead.
      float getFloat​(Object instance)
      Get the float value of this field on the given object instance.
      int getInt​(Object instance)
      Get the integer value of this field on the given object instance.
      Kind getKind()
      Get the kind of field.
      long getLong​(Object instance)
      Get the long value of this field on the given object instance.
      String getName()
      Get the name of the field.
      Object getObject​(Object instance)
      Get the object value of this field on the given object instance.
      int getRecordComponentIndex()
      Getter for the record component index.
      Object getRecordComponentValue​(Object obj)
      Getter for the record component value.
      short getShort​(Object instance)
      Get the short value of this field on the given object instance.
      Class<?> getType()
      Get the field type.
      boolean isAccessible()
      Determine if this object may be used to get or set an object field value.
      boolean isUnshared()
      Determine whether this field is marked as "unshared".
      void readFrom​(Object instance, ObjectInput input)
      Read the field value from the stream.
      void setBoolean​(Object instance, boolean value)
      Set the boolean value of this field on the given object instance.
      void setByte​(Object instance, byte value)
      Set the byte value of this field on the given object instance.
      void setChar​(Object instance, char value)
      Set the char value of this field on the given object instance.
      void setDouble​(Object instance, double value)
      Set the double value of this field on the given object instance.
      void setFloat​(Object instance, float value)
      Set the float value of this field on the given object instance.
      void setInt​(Object instance, int value)
      Set the integer value of this field on the given object instance.
      void setLong​(Object instance, long value)
      Set the long value of this field on the given object instance.
      void setObject​(Object instance, Object value)
      Set the object value of this field on the given object instance.
      void setShort​(Object instance, short value)
      Set the short value of this field on the given object instance.
      void writeTo​(Object instance, ObjectOutput output)  
    • Constructor Detail

      • SerializableField

        public SerializableField​(Class<?> type,
                                 String name,
                                 boolean unshared)
    • Method Detail

      • getField

        @Deprecated
        public Field getField()
        Deprecated.
        As of Java 9, accessible fields are generally disallowed; use the #setXXX(Object,value) methods instead.
        Get the reflection Field for this serializable field. The resultant field will be accessible.
        Returns:
        the reflection field
      • isAccessible

        public boolean isAccessible()
        Determine if this object may be used to get or set an object field value.
        Returns:
        true if this object may be used to get or set an object field value, false otherwise
      • getName

        public String getName()
        Get the name of the field.
        Returns:
        the name
      • isUnshared

        public boolean isUnshared()
        Determine whether this field is marked as "unshared".
        Returns:
        true if the field is unshared
      • getKind

        public Kind getKind()
        Get the kind of field.
        Returns:
        the kind
      • setBoolean

        public void setBoolean​(Object instance,
                               boolean value)
                        throws ClassCastException,
                               IllegalArgumentException
        Set the boolean value of this field on the given object instance.
        Parameters:
        instance - the object instance (must not be null, must be of the correct type)
        value - the value to set
        Throws:
        ClassCastException - if instance or the field is not of the correct type
        IllegalArgumentException - if this instance has no reflection field set on it
      • setChar

        public void setChar​(Object instance,
                            char value)
                     throws ClassCastException,
                            IllegalArgumentException
        Set the char value of this field on the given object instance.
        Parameters:
        instance - the object instance (must not be null, must be of the correct type)
        value - the value to set
        Throws:
        ClassCastException - if instance or the field is not of the correct type
        IllegalArgumentException - if this instance has no reflection field set on it
      • setShort

        public void setShort​(Object instance,
                             short value)
                      throws ClassCastException,
                             IllegalArgumentException
        Set the short value of this field on the given object instance.
        Parameters:
        instance - the object instance (must not be null, must be of the correct type)
        value - the value to set
        Throws:
        ClassCastException - if instance or the field is not of the correct type
        IllegalArgumentException - if this instance has no reflection field set on it
      • setInt

        public void setInt​(Object instance,
                           int value)
                    throws ClassCastException,
                           IllegalArgumentException
        Set the integer value of this field on the given object instance.
        Parameters:
        instance - the object instance (must not be null, must be of the correct type)
        value - the value to set
        Throws:
        ClassCastException - if instance or the field is not of the correct type
        IllegalArgumentException - if this instance has no reflection field set on it
      • setLong

        public void setLong​(Object instance,
                            long value)
                     throws ClassCastException,
                            IllegalArgumentException
        Set the long value of this field on the given object instance.
        Parameters:
        instance - the object instance (must not be null, must be of the correct type)
        value - the value to set
        Throws:
        ClassCastException - if instance or the field is not of the correct type
        IllegalArgumentException - if this instance has no reflection field set on it
      • setFloat

        public void setFloat​(Object instance,
                             float value)
                      throws ClassCastException,
                             IllegalArgumentException
        Set the float value of this field on the given object instance.
        Parameters:
        instance - the object instance (must not be null, must be of the correct type)
        value - the value to set
        Throws:
        ClassCastException - if instance or the field is not of the correct type
        IllegalArgumentException - if this instance has no reflection field set on it
      • setDouble

        public void setDouble​(Object instance,
                              double value)
                       throws ClassCastException,
                              IllegalArgumentException
        Set the double value of this field on the given object instance.
        Parameters:
        instance - the object instance (must not be null, must be of the correct type)
        value - the value to set
        Throws:
        ClassCastException - if instance or the field is not of the correct type
        IllegalArgumentException - if this instance has no reflection field set on it
      • getRecordComponentValue

        public Object getRecordComponentValue​(Object obj)
        Getter for the record component value.
        Parameters:
        obj - The object to obtain the record component value
        Returns:
        The record component value for this obj
      • getRecordComponentIndex

        public int getRecordComponentIndex()
        Getter for the record component index.
        Returns:
        The record component index or -1