Class BuildingEvaluator
java.lang.Object
ca.marcusdunn.jsonlens.path.evaluator.BuildingEvaluator
An evaluator with building function extensions. It accepts only models that implement both
JsonModel and JsonFactory.
JsonPathEvaluator.withFunctions(List, List) makes a building evaluator. It works as a
JsonPathEvaluator, but the compiler rejects a read-only model:
JsonPathParser parser = JsonPathParser.withFunctions(List.of(Upper.SIGNATURE)).orElse(null);
BuildingEvaluator evaluator =
JsonPathEvaluator.withFunctions(List.of(), List.of(new Upper())).orElse(null);
JsonPathQuery query = parser.parse("$[?upper(@) == upper('abc')]").orElse(null);
// JacksonJsonModel implements JsonModel and JsonFactory. A read-only model does not compile here.
List<Node<JsonNode>> nodes = evaluator.evaluate(query, root, JacksonJsonModel.INSTANCE).orElse(List.of());
// nodes: the paths $[0] and $[1]
A building evaluator is immutable and safe for use by more than one thread.
-
Method Summary
Modifier and TypeMethodDescription<N, M extends JsonModel<N> & JsonFactory<N>>
Result<List<Node<N>>, EvaluationError> evaluate(JsonPathQuery query, N root, M model) Applies a query to a JSON value.Returns the signatures of the functions that this evaluator has.limits()Returns the limits of this evaluator.withLimits(JsonPathEvaluator.Limits limits) Returns an evaluator with the same functions and other limits.
-
Method Details
-
withLimits
Returns an evaluator with the same functions and other limits.- Parameters:
limits- the limits- Returns:
- the evaluator
-
limits
-
functions
Returns the signatures of the functions that this evaluator has.- Returns:
- the signatures, the standard functions first
-
evaluate
public <N, M extends JsonModel<N> & JsonFactory<N>> Result<List<Node<N>>, EvaluationError> evaluate(JsonPathQuery query, N root, M model) Applies a query to a JSON value. SeeJsonPathEvaluator.evaluate(JsonPathQuery, Object, JsonModel).- Type Parameters:
N- the node typeM- the type of the model- Parameters:
query- the queryroot- the query argument: the root node valuemodel- the model for the node type, which can also build nodes- Returns:
- the nodelist, or an error
-