IntrospectionPropertyAccessor class final
A PropertyAccessor that reads and writes the properties of
@Introspected classes, using the metadata the code generator wrote
for them.
It is how expressions see your own classes without reflection: the
generator describes each @Introspected class in a
BeanIntrospection, registered in a BeanIntrospector. Both contexts
already have one over BeanIntrospector.shared, and an application
context adds one over its own introspector for @Value('#{...}').
Create one yourself only for another introspector. A written value
that is not of the property type is converted with the context's type
converter when it can be; others (an English for a Greeter
property) are passed as they are.
// A Person described by the introspector of a plugin, not the shared
// one: `address.city` is read and `age` set from a string.
final context = StandardEvaluationContext(person)
..addPropertyAccessor(IntrospectionPropertyAccessor(pluginIntrospector));
final parser = SpelExpressionParser();
parser.parseExpression('address.city').getValue(context);
parser.parseExpression('age').setValue(context, null, '7'); // age = 7
Spring (Java):
// ReflectivePropertyAccessor is registered by default:
StandardEvaluationContext context = new StandardEvaluationContext(person);
parser.parseExpression("address.city").getValue(context);
parser.parseExpression("age").setValue(context, "7");
- Implemented types
Constructors
- IntrospectionPropertyAccessor(BeanIntrospector introspector)
-
Reads the classes described in
introspector.const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- introspector → BeanIntrospector
-
The registry the descriptions of the targets' classes come from.
final
- 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 -
newValue(
Object target, String name) → Object? -
A new, empty value for property
nameoftarget: an empty list, set or map of the declared element types, or an instance of an introspected class with a no-argument constructor;nullwhen the type is not known well enough. -
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