Class BuildingEvaluator

java.lang.Object
ca.marcusdunn.jsonlens.path.evaluator.BuildingEvaluator

public final class BuildingEvaluator extends Object

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.