Class JsonNodeUtils
JsonNode objects and evaluating conditions.
Provides methods for:
- Converting
JsonNodeinstances to their corresponding Java types - Evaluating comparison conditions between values
- Safely comparing
Comparablevalues of potentially different types - Safely navigating JSON structures using a dot-separated path.
This class is designed to be non-instantiable and should only be accessed via static methods.
- Since:
- 1.0
- Author:
- Bonitasoft
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault value returned when the redirection name cannot be determined.static final StringOperator constant for contains comparison.static final StringOperator constant for equals comparison.static final StringOperator constant for equals comparison (symbol form).static final StringOperator constant for greater or equal comparison.static final StringOperator constant for greater or equal comparison (symbol form).static final StringOperator constant for greater than comparison.static final StringOperator constant for greater than comparison (symbol form).static final StringOperator constant for is empty check.static final StringOperator constant for is not empty check.static final StringOperator constant for less or equal comparison.static final StringOperator constant for less or equal comparison (symbol form).static final StringOperator constant for less than comparison.static final StringOperator constant for less than comparison (symbol form).static final StringOperator constant for not contains comparison.static final StringOperator constant for not equals comparison.static final StringOperator constant for not equals comparison (symbol form). -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompareValues(Comparable<?> actual, Comparable<?> expected) Compares twoComparablevalues in a type-safe manner.static ObjectconvertJsonNodeToObject(com.fasterxml.jackson.databind.JsonNode node) Converts aJsonNodeto its corresponding Java object type.static com.fasterxml.jackson.databind.JsonNodeconvertStringToJsonNode(String jsonString) Converts a JSON string to aJsonNode.static booleanevaluateAllConditions(com.fasterxml.jackson.databind.JsonNode conditionsNode, BiFunction<String, String, String> dataValueResolver) Evaluates all conditions in a JSON array, returning true only if ALL conditions are met.static booleanevaluateCondition(Object currentValue, String operator, Object expectedValue) Evaluates a condition comparing two values using the specified operator.static StringgetRedirectionName(com.fasterxml.jackson.databind.JsonNode redirection) Retrieves the redirection name from a JSON node, supporting both old and new data structures.static StringgetTargetStep(com.fasterxml.jackson.databind.JsonNode redirection) Retrieves the target step from a JSON node, supporting both old and new data structures.static StringgetTextValueByPath(com.fasterxml.jackson.databind.JsonNode rootNode, String path) Retrieves the text value at the specified path from aJsonNode.static StringgetTextValueByPath(String jsonString, String path) Retrieves the text value at the specified path from a JSON string.static com.fasterxml.jackson.databind.JsonNodegetValueByPath(com.fasterxml.jackson.databind.JsonNode rootNode, String path) Safely retrieves the value of a field from a JSON structure using a dot-separated path.static com.fasterxml.jackson.databind.JsonNodegetValueByPath(String jsonString, String path) Safely retrieves the value of a field from a JSON string using a dot-separated path.
-
Field Details
-
OP_EQUALS
Operator constant for equals comparison.- See Also:
-
OP_EQUALS_SYMBOL
Operator constant for equals comparison (symbol form).- See Also:
-
OP_NOT_EQUALS
Operator constant for not equals comparison.- See Also:
-
OP_NOT_EQUALS_SYMBOL
Operator constant for not equals comparison (symbol form).- See Also:
-
OP_CONTAINS
Operator constant for contains comparison.- See Also:
-
OP_NOT_CONTAINS
Operator constant for not contains comparison.- See Also:
-
OP_GREATER_THAN
Operator constant for greater than comparison.- See Also:
-
OP_GREATER_THAN_SYMBOL
Operator constant for greater than comparison (symbol form).- See Also:
-
OP_LESS_THAN
Operator constant for less than comparison.- See Also:
-
OP_LESS_THAN_SYMBOL
Operator constant for less than comparison (symbol form).- See Also:
-
OP_GREATER_OR_EQUAL
Operator constant for greater or equal comparison.- See Also:
-
OP_GREATER_OR_EQUAL_SYMBOL
Operator constant for greater or equal comparison (symbol form).- See Also:
-
OP_LESS_OR_EQUAL
Operator constant for less or equal comparison.- See Also:
-
OP_LESS_OR_EQUAL_SYMBOL
Operator constant for less or equal comparison (symbol form).- See Also:
-
OP_IS_EMPTY
Operator constant for is empty check.Evaluates to
trueif the value is null, an empty string, or a string containing only whitespace characters.- See Also:
-
OP_IS_NOT_EMPTY
Operator constant for is not empty check.Evaluates to
trueif the value is not null, not an empty string, and not a string containing only whitespace characters.- See Also:
-
DEFAULT_REDIRECTION_NAME
Default value returned when the redirection name cannot be determined.- See Also:
-
-
Method Details
-
convertJsonNodeToObject
Converts aJsonNodeto its corresponding Java object type.The conversion follows these rules:
- Parameters:
node- the JsonNode to convert (may be null)- Returns:
- the converted Java object, or null if the node is null or represents a JSON null
-
getValueByPath
public static com.fasterxml.jackson.databind.JsonNode getValueByPath(com.fasterxml.jackson.databind.JsonNode rootNode, String path) Safely retrieves the value of a field from a JSON structure using a dot-separated path.This method prevents
NullPointerExceptionby safely navigating through nested objects.- Parameters:
rootNode- the startingJsonNode(e.g., the root of the JSON structure).path- the dot-separated path to the desired field (e.g., "subject", "recipients.type").- Returns:
- the
JsonNoderepresenting the value at the specified path, ornullif the path is invalid, the field does not exist, or the value is JSON null.
-
getValueByPath
public static com.fasterxml.jackson.databind.JsonNode getValueByPath(String jsonString, String path) Safely retrieves the value of a field from a JSON string using a dot-separated path.This is a convenience method that first converts the JSON string to a
JsonNodeand then navigates to the specified path.- Parameters:
jsonString- the JSON string to parse (e.g., "{\"name\": \"John\", \"address\": {\"city\": \"Madrid\"}}").path- the dot-separated path to the desired field (e.g., "address.city").- Returns:
- the
JsonNoderepresenting the value at the specified path, ornullif the JSON is invalid, the path is invalid, the field does not exist, or the value is JSON null.
-
getTextValueByPath
public static String getTextValueByPath(com.fasterxml.jackson.databind.JsonNode rootNode, String path) Retrieves the text value at the specified path from aJsonNode.This is a convenience method that navigates to the specified path and returns the value as a plain
String(without JSON quotes). UnlikegetValueByPath(JsonNode, String)which returns aJsonNode, this method directly returns the text representation.Usage Example:
JsonNode root = objectMapper.readTree("{\"user\": {\"name\": \"John\"}}"); String name = JsonNodeUtils.getTextValueByPath(root, "user.name"); // Returns: "John" (without quotes)- Parameters:
rootNode- the startingJsonNode(e.g., the root of the JSON structure).path- the dot-separated path to the desired field (e.g., "user.name", "address.city").- Returns:
- the text value at the specified path, or
nullif the path is invalid, the field does not exist, or the value is JSON null.
-
getTextValueByPath
Retrieves the text value at the specified path from a JSON string.This is a convenience method that first parses the JSON string, navigates to the specified path, and returns the value as a plain
String(without JSON quotes).Usage Example:
String json = "{\"address\": {\"city\": \"Madrid\", \"zip\": \"28001\"}}"; String city = JsonNodeUtils.getTextValueByPath(json, "address.city"); // Returns: "Madrid" (without quotes)- Parameters:
jsonString- the JSON string to parse (e.g., "{\"name\": \"John\"}").path- the dot-separated path to the desired field (e.g., "address.city").- Returns:
- the text value at the specified path, or
nullif the JSON is invalid, the path is invalid, the field does not exist, or the value is JSON null.
-
convertStringToJsonNode
Converts a JSON string to aJsonNode.This method safely parses a JSON string and returns the corresponding
JsonNode. If the input is null, empty, or not valid JSON, it returnsnulland logs the error.- Parameters:
jsonString- the JSON string to parse (may be null or empty).- Returns:
- the parsed
JsonNode, ornullif the input is null, empty, or invalid JSON.
-
evaluateCondition
Evaluates a condition comparing two values using the specified operator.Supported operators (case-insensitive):
equalsor==: equality comparisonnotequalsor!=: inequality comparisoncontains: string containment checkgreaterthanor>: greater than comparisonlessthanor<: less than comparisongreaterorequalor>=: greater than or equal comparisonlessorequalor<=: less than or equal comparison
- Parameters:
currentValue- the current value to compare (may be null)operator- the comparison operator (case-insensitive)expectedValue- the expected value to compare against (may be null)- Returns:
trueif the condition is satisfied,falseotherwise
-
compareValues
Compares twoComparablevalues in a type-safe manner.Comparison rules:
- Parameters:
actual- the actual value to compare (must not be null)expected- the expected value to compare against (must not be null)- Returns:
- a negative integer, zero, or a positive integer as the actual value is less than, equal to, or greater than the expected value
- Throws:
NullPointerException- if actual or expected is null
-
evaluateAllConditions
public static boolean evaluateAllConditions(com.fasterxml.jackson.databind.JsonNode conditionsNode, BiFunction<String, String, String> dataValueResolver) Evaluates all conditions in a JSON array, returning true only if ALL conditions are met.This method is designed for evaluating process conditions where each condition references a step and field, compares against an expected value using an operator. The actual data retrieval is delegated to the caller via the
dataValueResolverfunction.Each condition in the array must have the following structure:
{ "stepRef": "step_identifier", "variableName": "field_name", "variableOperator": "equals", "variableValue": "expected_value" }The method short-circuits on the first failing condition (uses
allMatch).- Parameters:
conditionsNode- the JSON array containing condition objects (may be null or empty)dataValueResolver- a function that takes (fieldRef, stepRef) and returns the current data value as a String, or null if not found- Returns:
trueif all conditions are met or if conditionsNode is null/empty,falseif any condition fails or has invalid structure
-
getRedirectionName
Retrieves the redirection name from a JSON node, supporting both old and new data structures.This method provides backward compatibility by checking:
- New structure:
parameters.name - Old structure:
name(directly on the node)
If neither structure contains the name, returns "Unknown".
- Parameters:
redirection- the JSON node containing redirection data (may be null)- Returns:
- the redirection name, or "Unknown" if not found
- New structure:
-
getTargetStep
Retrieves the target step from a JSON node, supporting both old and new data structures.This method provides backward compatibility by checking:
- New structure:
parameters.targetStep - Old structure:
targetStep(directly on the node)
If neither structure contains the target step, returns
null.- Parameters:
redirection- the JSON node containing redirection data (may be null)- Returns:
- the target step identifier, or
nullif not found
- New structure:
-