Class FunctionAccessor<T>
java.lang.Object
com.alibaba.fastjson2.introspect.FunctionAccessor<T>
- Type Parameters:
T- the type of the object containing the property
- All Implemented Interfaces:
PropertyAccessor
Abstract base class for function-based property accessors.
Provides common functionality for accessing object properties using getter and setter functions.
This allows for accessing properties through functional interfaces rather than direct field access
or method invocation, providing flexibility in how properties are accessed.
Implements PropertyAccessor interface using functional interfaces for property access, providing efficient property access for serialization and deserialization operations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final BiFunction<PropertyAccessor, Throwable, RuntimeException> protected final ObjectThe getter function for accessing the property valueprotected final StringThe name of the property being accessedprotected final Class<?> The runtime class of the propertyprotected final TypeThe generic type of the propertyprotected final ObjectThe setter function for setting the property value -
Constructor Summary
ConstructorsConstructorDescriptionFunctionAccessor(String name, Type propertyType, Class<?> propertyClass, Object getter, Object setter) FunctionAccessor(String name, Type propertyType, Class<?> propertyClass, Object getter, Object setter, BiFunction<PropertyAccessor, Throwable, RuntimeException> exceptionHandler) Constructs a FunctionAccessor with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionfinal Stringname()Returns the name of the property being accessed.final Class<?> Returns the runtime class of the property.final TypeReturns the generic type of the property.final booleanChecks if the property supports getting values.final booleanChecks if the property supports setting values.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PropertyAccessor
getBooleanValue, getByteValue, getCharValue, getDoubleValue, getFloatValue, getIntValue, getLongValue, getObject, getShortValue, setBooleanValue, setByteValue, setCharValue, setDoubleValue, setFloatValue, setIntValue, setLongValue, setObject, setShortValue
-
Field Details
-
name
The name of the property being accessed -
propertyType
The generic type of the property -
propertyClass
The runtime class of the property -
getter
The getter function for accessing the property value -
setter
The setter function for setting the property value -
exceptionHandler
-
-
Constructor Details
-
FunctionAccessor
-
FunctionAccessor
public FunctionAccessor(String name, Type propertyType, Class<?> propertyClass, Object getter, Object setter, BiFunction<PropertyAccessor, Throwable, RuntimeException> exceptionHandler) Constructs a FunctionAccessor with the specified parameters.- Parameters:
name- the name of the propertypropertyType- the generic type of the propertypropertyClass- the runtime class of the propertygetter- the getter function for accessing the property valuesetter- the setter function for setting the property value
-
-
Method Details
-
name
Description copied from interface:PropertyAccessorReturns the name of the property being accessed.- Specified by:
namein interfacePropertyAccessor- Returns:
- the property name
-
supportGet
public final boolean supportGet()Checks if the property supports getting values. A property supports getting if a getter function is provided.- Specified by:
supportGetin interfacePropertyAccessor- Returns:
- true if the getter function is not null, false otherwise
-
supportSet
public final boolean supportSet()Checks if the property supports setting values. A property supports setting if a setter function is provided.- Specified by:
supportSetin interfacePropertyAccessor- Returns:
- true if the setter function is not null, false otherwise
-
propertyClass
Description copied from interface:PropertyAccessorReturns the runtime class of the property.- Specified by:
propertyClassin interfacePropertyAccessor- Returns:
- the property class
-
propertyType
Description copied from interface:PropertyAccessorReturns the generic type of the property.- Specified by:
propertyTypein interfacePropertyAccessor- Returns:
- the property type
-