FunctionPropertyAccessor<T extends Object> class
final
A PropertyAccessor for objects of type T, built from one getter
(and optionally one setter) function per property name.
Use it to make a class readable in expressions when it is not
@Introspected, for instance a class from another package: list the
properties expressions may see, nothing else is exposed.
IntrospectionPropertyAccessor does the same for @Introspected
classes from generated metadata.
// `name` can be read and assigned on a User.
final context = StandardEvaluationContext(user)
..addPropertyAccessor(FunctionPropertyAccessor<User>(
getters: {'name': (u) => u.name},
setters: {'name': (u, v) => u.name = v! as String},
));
SpelExpressionParser().parseExpression('name').getValue(context);
SpelExpressionParser()
.parseExpression("name = 'Ada'")
.getValue(context);
Spring (Java):
// Spring reads getName()/setName() by reflection
// (ReflectivePropertyAccessor), so no registration is needed:
parser.parseExpression("name")
.getValue(new StandardEvaluationContext(user));
- Implemented types
Constructors
-
FunctionPropertyAccessor({Map<
String, Object? Function(T target)> getters = const {}, Map<String, void Function(T target, Object? value)> setters = const {}}) -
Exposes
getters(readable properties) andsetters(writable properties) ofT, keyed by property name. A setter receives the value unconverted, so it casts it itself.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
canRead(
EvaluationContext context, Object target, String name) → bool -
Whether this accessor handles reading property
nameoftarget;falselets the next accessor try.targetis nevernull.override -
canWrite(
EvaluationContext context, Object target, String name) → bool -
Whether this accessor handles writing property
nameoftarget; returnfalsefor read-only properties.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
EvaluationContext context, Object target, String name) → Object? -
The value of property
nameoftarget; only called after canRead returnedtrue.override -
toString(
) → String -
A string representation of this object.
inherited
-
write(
EvaluationContext context, Object target, String name, Object? newValue) → void -
Stores
newValuein propertynameoftarget; only called after canWrite returnedtrue.override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited