Class FieldAccessor

java.lang.Object
com.alibaba.fastjson2.introspect.FieldAccessor
All Implemented Interfaces:
PropertyAccessor

public abstract class FieldAccessor extends Object implements PropertyAccessor
Abstract base class for field-based property accessors. Provides common functionality for accessing object fields using reflection. Handles field metadata and determines if the field supports setting based on whether the field is declared as final.

Implements PropertyAccessor interface using direct field access through reflection, providing efficient property access for serialization and deserialization operations.

  • Field Details

    • field

      protected final Field field
      The underlying Field object being accessed
    • fieldName

      protected final String fieldName
      The name of the field
    • propertyClass

      protected final Class<?> propertyClass
      The runtime class of the field
    • propertyType

      protected final Type propertyType
      The generic type of the field
    • supportSet

      protected final boolean supportSet
      Flag indicating whether the field supports setting values
  • Constructor Details

    • FieldAccessor

      protected FieldAccessor(Field field)
      Constructs a FieldAccessor for the given field.
      Parameters:
      field - the field to be accessed
  • Method Details

    • field

      public final Field field()
      Returns the underlying Field object.
      Returns:
      the Field object
    • propertyClass

      public final Class<?> propertyClass()
      Description copied from interface: PropertyAccessor
      Returns the runtime class of the property.
      Specified by:
      propertyClass in interface PropertyAccessor
      Returns:
      the property class
    • propertyType

      public final Type propertyType()
      Description copied from interface: PropertyAccessor
      Returns the generic type of the property.
      Specified by:
      propertyType in interface PropertyAccessor
      Returns:
      the property type
    • name

      public final String name()
      Description copied from interface: PropertyAccessor
      Returns the name of the property being accessed.
      Specified by:
      name in interface PropertyAccessor
      Returns:
      the property name
    • supportGet

      public final boolean supportGet()
      Description copied from interface: PropertyAccessor
      Checks if the property supports getting values.
      Specified by:
      supportGet in interface PropertyAccessor
      Returns:
      true if the property can be read, false otherwise
    • supportSet

      public final boolean supportSet()
      Description copied from interface: PropertyAccessor
      Checks if the property supports setting values.
      Specified by:
      supportSet in interface PropertyAccessor
      Returns:
      true if the property can be written, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object