MapAccessor class final

A PropertyAccessor that treats the entries of a map as properties, so user.name works when user is a map such as decoded JSON.

Both contexts register it by default (unless built with SimpleEvaluationContext.forPropertyAccessors), so you rarely create one. A key that is not in the map is not readable here: the next accessor is asked, and the expression fails if none can read it (map['missing'] gives null instead). Writing stores the key, new or not; a value of the wrong type for a typed map fails with exceptionDuringPropertyWrite (EL1034E).

// A JSON payload read without a class.
final data = {'user': {'name': 'Ada'}};
SpelExpressionParser()
    .parseExpression('user.name')
    .getValue(null, data); // 'Ada'

Spring (Java):

StandardEvaluationContext context = new StandardEvaluationContext(data);
context.addPropertyAccessor(new MapAccessor());
parser.parseExpression("user.name").getValue(context);
Implemented types

Constructors

MapAccessor()
Creates the accessor (stateless).
const

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 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
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