Skip to content

Spring Expression Language

Matt Magoffin edited this page Mar 22, 2023 · 2 revisions

The Spring Expression Language (spel) is a general purpose language suited for reading data properties and performing simple operations using a simple syntax. See SpEL Syntax for information on the language syntax.

Root object

When an expression is evaluated, it will be given a root object that serves as the object that the expression can make references to (for example, read the properties of). You must consult the documentation for the service making use of expressions to understand what the root object is, and what properties it exposes to the expression.

Variable names

Variable names are only allowed to contain specific characters. When expressions are evaluated, any variables provided to the expression will encode unsupported characters as hexadecimal values. You must consult the documentation for the service making use of expressions to understand what variables are provided to the expression, if any.

The following sets of characters are allowed:

  • a - z
  • A - Z
  • 0 - 9
  • _
  • $

The name may not start with a number. Any illegal character will be replaced by a hexadecimal encoding of the character's raw value, using lower case letters. For example:

  • Data+ becomes Data2b
  • Data- becomes Data2d

There are online tools available (for example here) to help with encoding characters.

Examples

Imagine a root object that looks like the following, expressed as JSON:

{
  "firstName" : "John",
  "lastName" : "Doe",
  "age" : 45,
  "favorites" : {
    "number" : 6,
    "color" : "red"
  },
  "aliases" : [
    "John",
    "Jonny",
    "Face"
  ]
}

Here are some sample expressions, and the result they yield:

Example Result
age * favorite.number 270
firstName + '"' + aliases[2] +'"' + lastName John "Face" Doe
Clone this wiki locally