This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Framework 6.0.25!

Collection Projection

Projection lets a collection drive the evaluation of a sub-expression, and the result is a new collection. The syntax for projection is .![projectionExpression]. For example, suppose we have a list of inventors but want the list of cities where they were born. Effectively, we want to evaluate placeOfBirth.city for every entry in the inventor list. The following example uses projection to do so:

  • Java

  • Kotlin

// evaluates to ["SmilJan", "Idvor"]
List placesOfBirth = parser.parseExpression("members.![placeOfBirth.city]")
		.getValue(societyContext, List.class);
// evaluates to ["SmilJan", "Idvor"]
val placesOfBirth = parser.parseExpression("members.![placeOfBirth.city]")
 		.getValue(societyContext) as List<*>

Projection is supported for arrays and anything that implements java.lang.Iterable or java.util.Map. When using a map to drive projection, the projection expression is evaluated against each entry in the map (represented as a Java Map.Entry). The result of a projection across a map is a list that consists of the evaluation of the projection expression against each map entry.