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 name of target; false lets the next accessor try. target is never null.
override
canWrite(EvaluationContext context, Object target, String name) → bool
Whether this accessor handles writing property name of target; return false for read-only properties.
override
newValue(Object target, String name) → Object?
A new, empty value for property name of target: an empty list, set or map of the declared element types, or an instance of an introspected class with a no-argument constructor; null when 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 name of target; only called after canRead returned true.
override
toString() → String
A string representation of this object.
inherited
write(EvaluationContext context, Object target, String name, Object? newValue) → void
Stores newValue in property name of target; only called after canWrite returned true.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited