Package com.api.jsonata4java
Class Expression
java.lang.Object
com.api.jsonata4java.Expression
- All Implemented Interfaces:
Serializable
Class to provide embedding and extending JSONata features
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAssign the binding to the environment preparing for evaluationvoidAssign the expression (variable or function declaration) to the variable name suppliedvoidclear()Remove all bindingscreateBindings(com.fasterxml.jackson.databind.JsonNode bindingObj) Establish a list of bindings for the given json objectcom.fasterxml.jackson.databind.JsonNodeevaluate(com.fasterxml.jackson.databind.JsonNode rootContext) Generate a result form the Expression's parsed expression and variable assignments or registered functionscom.fasterxml.jackson.databind.JsonNodeevaluate(com.fasterxml.jackson.databind.JsonNode rootContext, long timeoutMS, int maxDepth) Generate a result form the Expression's parsed expression and variable assignments or registered functionscom.fasterxml.jackson.databind.JsonNodeevaluate(com.fasterxml.jackson.databind.JsonNode rootContext, com.fasterxml.jackson.databind.JsonNode bindingObj) Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings objectcom.fasterxml.jackson.databind.JsonNodeevaluate(com.fasterxml.jackson.databind.JsonNode rootContext, com.fasterxml.jackson.databind.JsonNode bindingObj, long timeoutMS, int maxDepth) Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings objectcom.fasterxml.jackson.databind.JsonNodeGenerate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindingscom.fasterxml.jackson.databind.JsonNodeevaluate(com.fasterxml.jackson.databind.JsonNode rootContext, List<Binding> bindings, long timeoutMS, int maxDepth) Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindingscom.fasterxml.jackson.databind.JsonNodeevaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext) Generate a result form the Expression's parsed expression and variable assignments or registered functions.com.fasterxml.jackson.databind.JsonNodeevaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, long timeoutMS, int maxDepth) Generate a result form the Expression's parsed expression and variable assignments or registered functions.com.fasterxml.jackson.databind.JsonNodeevaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, com.fasterxml.jackson.databind.JsonNode bindingObj) Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings objectcom.fasterxml.jackson.databind.JsonNodeevaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, com.fasterxml.jackson.databind.JsonNode bindingObj, long timeoutMS, int maxDepth) Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings object.com.fasterxml.jackson.databind.JsonNodeevaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, List<Binding> bindings) Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings.com.fasterxml.jackson.databind.JsonNodeevaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, List<Binding> bindings, long timeoutMS, int maxDepth) Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings.static ExpressionGenerate a new Expression based on evaluating the supplied expressionstatic voidTesting the various methods based on https://docs.jsonata.org/embedding-extending#expressionregisterfunctionname-implementation-signaturevoidregisterFunction(String fctName, String implementation) Registers a function implementation (declaration) by name
-
Constructor Details
-
Expression
Constructor for Expression- Parameters:
expression- the logic to be parsed for later execution via evaluate methods- Throws:
ParseExceptionIOException
-
-
Method Details
-
createBindings
public static List<Binding> createBindings(com.fasterxml.jackson.databind.JsonNode bindingObj) throws ParseException Establish a list of bindings for the given json object- Parameters:
bindingObj- the json to calculate the bindings for- Returns:
- the list of bindings for the provided json
- Throws:
ParseException
-
jsonata
Generate a new Expression based on evaluating the supplied expression- Parameters:
expression- the logic to be parsed for later execution via the evaluate methods- Returns:
- new Expression object
- Throws:
ParseExceptionIOException
-
main
Testing the various methods based on https://docs.jsonata.org/embedding-extending#expressionregisterfunctionname-implementation-signature- Parameters:
args- not used
-
assign
Assign the binding to the environment preparing for evaluation- Parameters:
binding-
-
assign
Assign the expression (variable or function declaration) to the variable name supplied- Parameters:
varname- name of the variable to map to a variable expression or function declaration expressionexpression- logic to be assigned to the variable name- Throws:
ParseExceptionIOException
-
clear
public void clear()Remove all bindings -
evaluate
public com.fasterxml.jackson.databind.JsonNode evaluate(com.fasterxml.jackson.databind.JsonNode rootContext) throws ParseException Generate a result form the Expression's parsed expression and variable assignments or registered functions- Parameters:
rootContext- JSON object specifying the content used to evaluate the expression- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions. A null will be returned if no match is found (note a JSON null will result in a JsonNode of type NullNode).
- Throws:
ParseException
-
evaluate
public com.fasterxml.jackson.databind.JsonNode evaluate(com.fasterxml.jackson.databind.JsonNode rootContext, com.fasterxml.jackson.databind.JsonNode bindingObj) throws ParseException, IOException Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings object- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressionbindingObj- a JSON object containing the assignments of variable names to variable expressions or function declarations- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the bindings object
- Throws:
ParseExceptionIOException
-
evaluate
public com.fasterxml.jackson.databind.JsonNode evaluate(com.fasterxml.jackson.databind.JsonNode rootContext, com.fasterxml.jackson.databind.JsonNode bindingObj, long timeoutMS, int maxDepth) throws ParseException, IOException, EvaluateException Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings object- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressionbindingObj- a JSON object containing the assignments of variable names to variable expressions or function declarationstimeoutMS- milliseconds allowed for the evaluation to occur. If it takes longer an exception is thrown. Must be positive number or exception is thrown.maxDepth- the maximum call stack depth allowed before an exception is thrown. Must be a positive number or an exception is thrown.- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the bindings object
- Throws:
ParseExceptionIOExceptionEvaluateException
-
evaluate
public com.fasterxml.jackson.databind.JsonNode evaluate(com.fasterxml.jackson.databind.JsonNode rootContext, List<Binding> bindings) throws ParseException Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressionbindings- assignments of variable names to variable expressions or function declarations- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings. A null will be returned if no match is found (note a JSON null will result in a JsonNode of type NullNode).
- Throws:
ParseException
-
evaluate
public com.fasterxml.jackson.databind.JsonNode evaluate(com.fasterxml.jackson.databind.JsonNode rootContext, List<Binding> bindings, long timeoutMS, int maxDepth) throws ParseException, EvaluateException Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressionbindings- assignments of variable names to variable expressions or function declarationstimeoutMS- milliseconds allowed for the evaluation to occur. If it takes longer an exception is thrown. Must be positive number or exception is thrown.maxDepth- the maximum call stack depth allowed before an exception is thrown. Must be a positive number or an exception is thrown.- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings. A null will be returned if no match is found (note a JSON null will result in a JsonNode of type NullNode).
- Throws:
ParseExceptionEvaluateException
-
evaluate
public com.fasterxml.jackson.databind.JsonNode evaluate(com.fasterxml.jackson.databind.JsonNode rootContext, long timeoutMS, int maxDepth) throws EvaluateException Generate a result form the Expression's parsed expression and variable assignments or registered functions- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressiontimeoutMS- milliseconds allowed for the evaluation to occur. If it takes longer an exception is thrown. Must be positive number or exception is thrown.maxDepth- the maximum call stack depth allowed before an exception is thrown. Must be a positive number or an exception is thrown.- Returns:
- the JsonNode resulting from the expression evaluation against the rootContext. A null will be returned if no match is found (note a JSON null will result in a JsonNode of type NullNode).
- Throws:
EvaluateException- If the given device event is invalid.
-
evaluateSynced
public com.fasterxml.jackson.databind.JsonNode evaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext) throws ParseException Generate a result form the Expression's parsed expression and variable assignments or registered functions. This method is synchronized to enable multi-threaded execution.- Parameters:
rootContext- JSON object specifying the content used to evaluate the expression- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions. A null will be returned if no match is found (note a JSON null will result in a JsonNode of type NullNode).
- Throws:
ParseException
-
evaluateSynced
public com.fasterxml.jackson.databind.JsonNode evaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, com.fasterxml.jackson.databind.JsonNode bindingObj) throws ParseException, IOException Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings object- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressionbindingObj- a JSON object containing the assignments of variable names to variable expressions or function declarations- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the bindings object
- Throws:
ParseExceptionIOException
-
evaluateSynced
public com.fasterxml.jackson.databind.JsonNode evaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, com.fasterxml.jackson.databind.JsonNode bindingObj, long timeoutMS, int maxDepth) throws ParseException, IOException, EvaluateException Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the bindings object. This method is synchronized to enable multi-threaded execution.- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressionbindingObj- a JSON object containing the assignments of variable names to variable expressions or function declarationstimeoutMS- milliseconds allowed for the evaluation to occur. If it takes longer an exception is thrown. Must be positive number or exception is thrown.maxDepth- the maximum call stack depth allowed before an exception is thrown. Must be a positive number or an exception is thrown.- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the bindings object
- Throws:
ParseExceptionIOExceptionEvaluateException
-
evaluateSynced
public com.fasterxml.jackson.databind.JsonNode evaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, List<Binding> bindings) throws ParseException Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings. This method is synchronized to enable multi-threaded execution.- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressionbindings- assignments of variable names to variable expressions or function declarations- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings. A null will be returned if no match is found (note a JSON null will result in a JsonNode of type NullNode).
- Throws:
ParseException
-
evaluateSynced
public com.fasterxml.jackson.databind.JsonNode evaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, List<Binding> bindings, long timeoutMS, int maxDepth) throws ParseException, EvaluateException Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings. This method is synchronized to enable multi-threaded execution.- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressionbindings- assignments of variable names to variable expressions or function declarationstimeoutMS- milliseconds allowed for the evaluation to occur. If it takes longer an exception is thrown. Must be positive number or exception is thrown.maxDepth- the maximum call stack depth allowed before an exception is thrown. Must be a positive number or an exception is thrown.- Returns:
- the result from executing the Expression's parsed expression and variable assignments or registered functions specified in the list of bindings. A null will be returned if no match is found (note a JSON null will result in a JsonNode of type NullNode).
- Throws:
ParseExceptionEvaluateException
-
evaluateSynced
public com.fasterxml.jackson.databind.JsonNode evaluateSynced(com.fasterxml.jackson.databind.JsonNode rootContext, long timeoutMS, int maxDepth) throws EvaluateException Generate a result form the Expression's parsed expression and variable assignments or registered functions. This method is synchronized to enable multi-threaded execution.- Parameters:
rootContext- JSON object specifying the content used to evaluate the expressiontimeoutMS- milliseconds allowed for the evaluation to occur. If it takes longer an exception is thrown. Must be positive number or exception is thrown.maxDepth- the maximum call stack depth allowed before an exception is thrown. Must be a positive number or an exception is thrown.- Returns:
- the JsonNode resulting from the expression evaluation against the rootContext. A null will be returned if no match is found (note a JSON null will result in a JsonNode of type NullNode).
- Throws:
EvaluateException- If the given device event is invalid.
-
registerFunction
public void registerFunction(String fctName, String implementation) throws ParseException, IOException Registers a function implementation (declaration) by name- Parameters:
fctName- the name of the functionimplementation- the function declaration- Throws:
ParseExceptionIOException
-