Skip to content

Built in predicates

Esta Nagy edited this page Jun 19, 2020 · 6 revisions

Here you can find all Predicates defined as part of the standard package.

How to use this document...

Predicates have a single purpose of evaluating input values and returning boolean values. This might or might not need any additional configuration as you will see form our examples.

Each predicate has a version when it was added to the app, a class implementing them, a name they are registered with, an input type, a parameter list defining how they can be configured, a description stating what they are supposed to do, and we will show an example configuration as well.

Predicate implementations

All Match predicate

Name: allMatch

Class: AllMatchPredicate

Since version: 1.1.0

Input type: Object

Parameters

Name Type Description
from Collection<Predicate<Opject>> The collection of Predicates we need to evaluate one by one to find the return value.

Description

This predicate returns true if all of the Predicates from the "from" collection returned true, false otherwise.

Example configuration

name: "deleteFrom"
path: "$.accounts[*]"
params:
  keepKey: # this is our predicate
    name: "allMatch"
    from:
      - name: "notNull"
      - name: "regex"
        pattern: ^[a-z]+$
      - name: "anyString" 

This example will match Strings that are not null and have lower case alpha characters only.

Any Match predicate

Name: anyMatch

Class: AnyMatchPredicate

Since version: 1.1.0

Input type: Object

Parameters

Name Type Description
from Collection<Predicate<Opject>> The collection of Predicates we need to evaluate one by one to find the return value.

Description

This predicate returns true if any of the Predicates from the "from" collection returned true, false otherwise.

Example configuration

name: "deleteFrom"
path: "$.accounts[*]"
params:
  keepKey: # this is our predicate
    name: "anyMatch"
    from:
      - name: "regex"
        pattern: ^[0-9]+$
      - name: "regex"
        pattern: ^[a-z]+$
      - name: "regex"
        pattern: ^[A-Z]+$ 

This example will match Strings that are using either only numeric or only lower case alpha or only upper case alpha characters.

Any String predicate

Name: anyString

Class: AnyStringPredicate

Since version: 1.0.0

Input type: String

Parameters: none

Description

This predicate returns true for any String.

Example configuration

name: "replace"
path: "$.accounts..lastName"
params:
  stringFunction:
    name: "regex"
    pattern: (?<firstName>[A-Za-z\-]+) (?<lastName>[A-Za-z\-]+)
    replacement: "${lastName}"
  predicate: # this is the node defining our predicate
    name: "anyString"

This example will match any String, essentially including all String nodes the JsonPath of our rule matches.

Contains key predicate

Name: containsKey

Class: ContainsKeyPredicate

Since version: 1.1.0

Input type: Map<String, Object>

Parameters

Name Type Description
key String The name of the key we want to check.

Description

This predicate observes the input as a Map and returns true if it has a key named exactly matching the value of the key parameter.

Example configuration

name: "deleteFrom"
path: "$.accounts[*]"
params:
  deleteValue: # this is our predicate
    name: "containsKey"
    key: "billing"

This example will match any values which have a key named "billing".

Eval on predicate

Name: evalOn

Class: EvalOnPredicate

Since version: 1.1.0

Input type: Map<String, Object>

Parameters

Name Type Description
childPath String The desired navigation we want to perform relative to the Map/Object we operate on.
predicate Predicate<Opject> The Predicate we need to evaluate after the navigation is done.

Description

This predicate attempts to convert the input to a Map representation and attempts to navigate using the keys of the Map as it is defined by the childPath parameter. The childPath parameter is split using a single dot '.' as delimiter to find the small steps we need to take one after the other. Once the navigation is done and reaches a valid path, we apply the predicate.

Example configuration

name: "deleteFrom"
path: "$.accounts[*]"
params:
  keepKey: # this is our predicate
    name: "evalOn"
    predicate:
      name: "regex"
      pattern: ^[0-9]+$
    childPath: "address.billing.zipCode"

This example will match if the value under the zipCode" key of the "billing" field of the "address" field is a numerical value as String.

Is Null predicate

Name: isNull

Class: IsNullPredicate

Since version: 1.1.0

Input type: Object

Parameters: none

Description

This predicate returns true for null.

Example configuration

name: "deleteFrom"
path: "$.accounts[*]"
params:
  predicate: # this is the node defining our predicate
    name: "isNull"

This example will match only Null values.

None Match predicate

Name: noneMatch

Class: NoneMatchPredicate

Since version: 1.1.0

Input type: Object

Parameters

Name Type Description
from Collection<Predicate<Opject>> The collection of Predicates we need to evaluate one by one to find the return value.

Description

This predicate returns true if none of the Predicates from the "from" collection returned true, false otherwise.

Example configuration

name: "deleteFrom"
path: "$.accounts[*]"
params:
  keepKey: # this is our predicate
    name: "noneMatch"
    from:
      - name: "regex"
        pattern: ^[0-9]+$
      - name: "regex"
        pattern: ^[a-z]+$

This example will match Strings that are using neither only numeric nor only lower case alpha characters.

Non Null predicate

Name: notNull

Class: NotNullPredicate

Since version: 1.1.0

Input type: Object

Parameters: none

Description

This predicate returns true for anything that is not null.

Example configuration

name: "deleteFrom"
path: "$.accounts[*]"
params:
  predicate: # this is the node defining our predicate
    name: "notNull"

This example will match all values.

Regex predicate

Name: regex

Class: RegexPredicate

Since version: 1.1.0

Input type: String

Parameters

Name Type Description
pattern String The regular expression we want to match.

Description

This predicate returns true if input value matches the regular expression defined in the "pattern" parameter.

Example configuration

name: "deleteFrom"
path: "$.accounts[*]"
params:
  keepKey: # this is our predicate
    name: "regex"
    pattern: ^[a-z]+$

This example will match Strings that are using only lower case alpha characters.

SpEL predicate

Name: SpEL

Class: SpringExpressionLanguagePredicate

Since version: 1.1.0

Input type: Object

Parameters

Name Type Description
expression String The SpEL expression we want to match.

Description

This predicate returns true if input value matches the SpEL expression defined in the "expression" parameter.

Example configuration

name: "deleteFrom"
path: "$.accounts[*]"
params:
  deleteValue: # this is our predicate
    name: "SpEL"
    expression: "T(java.util.Objects).isNull(#root)" 

This example will match null values.