Class Selection

java.lang.Object
org.springframework.expression.spel.ast.SpelNodeImpl
org.springframework.expression.spel.ast.Selection
All Implemented Interfaces:
Opcodes, SpelNode

public class Selection extends SpelNodeImpl
Represents selection over a Map, Iterable, or array.

For example, {1,2,3,4,5,6,7,8,9,10}.?[#isEven(#this)] evaluates to [2, 4, 6, 8, 10].

Basically a subset of the input data is returned based on the evaluation of the expression supplied as selection criteria.

Null-safe Selection

Null-safe selection is supported via the '?.?' operator. For example, 'names?.?[#this.length > 5]' will evaluate to null if names is null and will otherwise evaluate to a sequence containing the names whose length is greater than 5. As of Spring Framework 7.0, null-safe selection also applies when performing selection on an Optional target. For example, if names is of type Optional<List<String>>, the expression 'names?.?[#this.length > 5]' will evaluate to null if names is null or empty and will otherwise evaluate to a sequence containing the names whose lengths are greater than 5, effectively names.get().stream().filter(s -> s.length() > 5).toList().

Since:
3.0
Author:
Andy Clement, Mark Fisher, Sam Brannen, Juergen Hoeller