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 TypeMethodDescriptionvoid
checkAmbiguity
(Set<JsonPath> jsonPaths) Validates if the input set of json path queries is ambiguous.Parses an input literal into aJsonPath
object.Parses an input literal into aJsonPath
object.
-
Constructor Details
-
JsonPathParser
public JsonPathParser()
-
-
Method Details
-
parse
Parses an input literal into aJsonPath
object. ThrowsIllegalArgumentException
when the input literal does not follow the jsonpath specification.- Parameters:
literal
- a jsonpath literal to be parsed.- Returns:
JsonPath
object parsed from the literal.
-
tryParse
Parses an input literal into aJsonPath
object. Returns null when the input literal does not follow the jsonpath specification.- Parameters:
literal
- a jsonpath literal to be parsed.- Returns:
- a
JsonPath
object parsed from the literal.
-
checkAmbiguity
Validates if the input set of json path queries is ambiguous. Throwsjava.lang.IllegalArgumentException#IllegalArgumentException
if 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
-