Class MethodAccessor

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

public abstract class MethodAccessor extends Object implements PropertyAccessor
Abstract base class for method-based property accessors. Provides common functionality for accessing object properties using getter and setter methods. This allows for accessing properties through standard getter/setter method pairs, providing flexibility in how properties are accessed compared to direct field access.

Implements PropertyAccessor interface using method invocation for property access, providing efficient property access for serialization and deserialization operations.

  • Field Details

    • name

      protected final String name
      The name of the property being accessed
    • propertyType

      protected final Type propertyType
      The generic type of the property
    • propertyClass

      protected final Class<?> propertyClass
      The runtime class of the property
    • getter

      protected final Method getter
      The getter method for accessing the property value
    • setter

      protected final Method setter
      The setter method for setting the property value
  • Constructor Details

    • MethodAccessor

      public MethodAccessor(String name, Type propertyType, Class<?> propertyClass, Method getter, Method setter)
      Constructs a MethodAccessor with the specified parameters.
      Parameters:
      name - the name of the property
      propertyType - the generic type of the property
      propertyClass - the runtime class of the property
      getter - the getter method for accessing the property value
      setter - the setter method for setting the property value
  • Method Details

    • 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()
      Checks if the property supports getting values. A property supports getting if a getter method is provided.
      Specified by:
      supportGet in interface PropertyAccessor
      Returns:
      true if the getter method is not null, false otherwise
    • supportSet

      public final boolean supportSet()
      Checks if the property supports setting values. A property supports setting if a setter method is provided.
      Specified by:
      supportSet in interface PropertyAccessor
      Returns:
      true if the setter method is not null, false otherwise
    • 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