Spring Expression Language to search anywhere in the object graph

In Spring Expression Language is it possible to perform an exhaustive search on an object graph and return the first node matching?

For example,

BookingEvent event = getEvent();
ExpressionParser parser = new SpelExpressionParser();
Expression exp = parser.parseExpression("metadata.bookerInfo.traveler.userBusinessInfo.employeeId");
Assertions.assertEquals("EM1", exp.getValue(event));

The above one works but in SpEL can I write an expression to find the employeedId anywhere under metadata or anywhere in the event object?

If yes, is it possible to return all employeeIds instead only the first one?

I am using spring-boot 3.0.11

Leave a Comment