Skip to content

Commit

Permalink
[NU-1836] Move converters from CONV util to extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Łukasz Bigorajski committed Oct 24, 2024
1 parent 0d8c7da commit bad9782
Show file tree
Hide file tree
Showing 12 changed files with 2,582 additions and 477 deletions.
17 changes: 5 additions & 12 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@
* [#6807](https://github.com/TouK/nussknacker/pull/6807) Add conversion functions to primitives to: `#CONV`:
* toNumberOrNull
* toString
* toBoolean
* toBooleanOrNull
* toInteger
* toIntegerOrNull
* toLong
* toLongOrNull
* toDouble
* toDoubleOrNull
* toBigInteger
* toBigIntegerOrNull
* toBigDecimal
* toBigDecimalOrNull
* [#6995](https://github.com/TouK/nussknacker/pull/6995) Add `toJson` and `toJsonString` conversions (in the `#CONV` helper)
* [#6995](https://github.com/TouK/nussknacker/pull/6995) Add `#BASE64` helper to decode/encode Base64 values
* [#6826](https://github.com/TouK/nussknacker/pull/6826) Security fix: added validation of expression used inside
Expand Down Expand Up @@ -76,6 +64,11 @@
* [#6958](https://github.com/TouK/nussknacker/pull/6958) Add message size limit in the "Kafka" exceptionHandler
* [#6988](https://github.com/TouK/nussknacker/pull/6988) Remove unused API classes: `MultiMap`, `TimestampedEvictableStateFunction`
* [#7000](https://github.com/TouK/nussknacker/pull/7000) Show all possible options for dictionary editor on open.
* [#7061](https://github.com/TouK/nussknacker/pull/7061) SpeL: add conversion to primitives extension methods:
* isBoolean/toBoolean/toBooleanOrNull
* isLong/toLong/toLongOrNull
* isDouble/toDouble/toDoubleOrNull
* isBigDecimal/toBigDecimal/toBigDecimalOrNull

## 1.17

Expand Down
20 changes: 14 additions & 6 deletions docs/scenarios_authoring/Spel.md
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,20 @@ More usage examples can be found in [this section](#conversions-between-datetime

Explicit conversions are available in utility classes and build-in java conversion mechanisms:

| Expression | Result | Type |
|-----------------------------------------------------------------|----------------------------|-----------------|
| `#NUMERIC.toNumber('42')` | 42 | Number |
| `#NUMERIC.toNumber('42').toString()` | '42' | String |
| `#DATE_FORMAT.parseOffsetDateTime('2018-10-23T12:12:13+00:00')` | 1540296720000 | OffsetDateTime |
| `#DATE_FORMAT.parseLocalDateTime('2018-10-23T12:12:13')` | 2018-10-23T12:12:13+00:00 | LocalDateTime |
| Expression | Result | Type |
|-----------------------------------------------------------------|---------------------------|----------------|
| `#NUMERIC.toNumber('42')` | 42 | Number |
| `#NUMERIC.toNumber('42').toString()` | '42' | String |
| `#DATE_FORMAT.parseOffsetDateTime('2018-10-23T12:12:13+00:00')` | 1540296720000 | OffsetDateTime |
| `#DATE_FORMAT.parseLocalDateTime('2018-10-23T12:12:13')` | 2018-10-23T12:12:13+00:00 | LocalDateTime |
| `'true'.toBoolean` | true | Boolean |
| `'11'.toLong` | 11 | Long |
| `'1.1'.toDouble` | 1.1 | Double |
| `2.1.toBigDecimal` | 2.1 | BigDecimal |

Functions which start with `to`, e.g. `toBoolean`, have their equivalents:
- to check if a given value can be converted to appropriate type, e.g. `'true'.isBoolean`.
- and to return null if conversion fails, e.g. `'false'.toBooleanOrNull'`.

### Casting

Expand Down
Loading

0 comments on commit bad9782

Please sign in to comment.