Skip to content

Commit

Permalink
add conversions examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Bigorajski committed Nov 15, 2024
1 parent 39e2788 commit 5672382
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion docs/scenarios_authoring/Spel.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ can be accessed in e.g. in following ways:
* `#exampleObjects['someNestedObject']['someFieldInNestedObject']`
* `#exampleObjects['someArrayWithObjects'][0]['someFieldInObjectInArray']`

Every unknown accessed field/element will produce `Unknown` data type which can be further navigated or [converted](#type-conversions) to a desired type.
Every unknown accessed field/element will produce `Unknown` data type, which can be further navigated or [converted](#type-conversions) to a desired type.

### Type conversions

Expand Down Expand Up @@ -292,6 +292,17 @@ the `to` prefix cast or convert a value to the desired type, and if the operatio
further. Functions with the `to` prefix and `OrNull` suffix cast or convert a value to the desired type,
and if the operation fails, a null value is returned.

Examples of conversions:

| Expression | Result | Type |
|----------------------------|--------|---------|
| `"123".canBeDouble` | true | Boolean |
| `"123".toDouble` | 123.0 | Double |
| `"abc".toDoubleOrNull` | null | Double |
| `"123".canBe('Double')` | true | Boolean |
| `"123".to('Double')` | 123.0 | Double |
| `"abc".toOrNull('Double')` | null | Double |

Conversions only make sense between specific types. We limit SpeL's suggestions to show only possible conversions.
Below is a matrix which shows which types can be converted with each other:

Expand Down

0 comments on commit 5672382

Please sign in to comment.