Package com.api.jsonata4java
Class Expression
- java.lang.Object
-
- com.api.jsonata4java.Expression
-
- All Implemented Interfaces:
Serializable
public class Expression extends Object implements Serializable
Class to provide embedding and extending JSONata features- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Expression(String expression)Constructor for Expression
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassign(Binding binding)Assign the binding to the environment preparing for evaluationvoidassign(String varname, String expression)Assign the expression (variable or function declaration) to the variable name suppliedvoidclear()Remove all bindingsstatic List<Binding>createBindings(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, 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, List<Binding> bindings)Generate a result form the Expression's parsed expression and variable assignments or registered functions specified in the list of bindingsstatic Expressionjsonata(String expression)Genearte a new Expression based on evaluating the supplied expressionstatic voidmain(String[] args)Testing 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 Detail
-
Expression
public Expression(String expression) throws ParseException, IOException
Constructor for Expression- Parameters:
expression- the logic to be parsed for later execution via evaluate methods- Throws:
ParseExceptionIOException
-
-
Method Detail
-
jsonata
public static Expression jsonata(String expression) throws ParseException, IOException
Genearte 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
-
createBindings
public static List<Binding> createBindings(com.fasterxml.jackson.databind.JsonNode bindingObj)
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
-
main
public static void main(String[] args)
Testing the various methods based on https://docs.jsonata.org/embedding-extending#expressionregisterfunctionname-implementation-signature- Parameters:
args- not used
-
assign
public void assign(Binding binding)
Assign the binding to the environment preparing for evaluation- Parameters:
binding-
-
clear
public void clear()
Remove all bindings
-
assign
public void assign(String varname, String expression) throws ParseException, IOException
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
-
evaluate
public com.fasterxml.jackson.databind.JsonNode evaluate(com.fasterxml.jackson.databind.JsonNode rootContext) throws ParseExceptionGenerate 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, List<Binding> bindings) throws ParseExceptionGenerate 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, com.fasterxml.jackson.databind.JsonNode bindingObj) throws ParseException, IOExceptionGenerate 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
-
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
-
-