Class JsonPathParser
java.lang.Object
dev.blaauwendraad.masker.json.path.JsonPathParser
Parses a jsonpath literal into a
JsonPath object.
The following features from jsonpath specification are not supported:
- Descendant segments
- Child segments
- Name selectors
- Array slice selectors
- Index selectors
- Filter selectors
- Function extensions
- Escape characters
The parser makes a couple of additional restrictions:
- Numbers as key names are disallowed
- A set of input jsonpath literals must not be ambiguous
$.*.b and $.a.b. In this case, we cannot match forward the segments.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckAmbiguity(Set<JsonPath> jsonPaths) Validates if the input set of JSONPath queries is ambiguous.Parses an input literal into aJsonPathobject.Parses an input literal into aJsonPathobject.
-
Constructor Details
-
JsonPathParser
public JsonPathParser()
-
-
Method Details
-
parse
Parses an input literal into aJsonPathobject. ThrowsIllegalArgumentExceptionwhen the input literal does not follow the jsonpath specification.- Parameters:
literal- a jsonpath literal to be parsed.- Returns:
JsonPathobject parsed from the literal.
-
tryParse
Parses an input literal into aJsonPathobject. Returns null when the input literal does not follow the jsonpath specification.- Parameters:
literal- a jsonpath literal to be parsed.- Returns:
- a
JsonPathobject parsed from the literal.
-
checkAmbiguity
Validates if the input set of JSONPath queries is ambiguous. Throwsjava.lang.IllegalArgumentException#IllegalArgumentExceptionif it is.The method does a lexical sort of input jsonpath queries, iterates over sorted values and checks if any local pair is ambiguous.
- Parameters:
jsonPaths- input set of jsonpath queries
-