Interface ParseError
- All Known Implementing Classes:
ParseError.ArgumentTypeMismatch, ParseError.ControlCharacter, ParseError.IntegerOutOfRange, ParseError.InvalidEscape, ParseError.InvalidInteger, ParseError.InvalidUtf8, ParseError.LiteralWithoutComparison, ParseError.NestingTooDeep, ParseError.NonSingularQuery, ParseError.NotComparable, ParseError.NumberOutOfRange, ParseError.UnexpectedCharacter, ParseError.UnexpectedEnd, ParseError.UnknownFunction, ParseError.UnpairedSurrogate, ParseError.ValueTypeInTest, ParseError.WrongArgumentCount
public sealed interface ParseError
permits ParseError.UnexpectedCharacter, ParseError.UnexpectedEnd, ParseError.InvalidUtf8, ParseError.UnpairedSurrogate, ParseError.ControlCharacter, ParseError.InvalidEscape, ParseError.InvalidInteger, ParseError.IntegerOutOfRange, ParseError.NumberOutOfRange, ParseError.UnknownFunction, ParseError.WrongArgumentCount, ParseError.ArgumentTypeMismatch, ParseError.NonSingularQuery, ParseError.NotComparable, ParseError.ValueTypeInTest, ParseError.LiteralWithoutComparison, ParseError.NestingTooDeep
The reason why a query is not well-formed or not valid (RFC 9535, Section 2.1).
Each error is a record, so a switch can match the errors that need special handling.
message() gives a description of all errors:
String describe = switch (JsonPathParser.standard().parse("$[?length(@.*) > 3]")) {
case Result.Ok(JsonPathQuery query) -> "valid: " + query;
case Result.Err(ParseError.NonSingularQuery(int position)) ->
"@.* can select more than one node, at position " + position;
case Result.Err(ParseError.UnknownFunction(int position, String name)) ->
"no function " + name;
case Result.Err(ParseError error) -> error.message(); // all other errors
};
// describe: "@.* can select more than one node, at position 10"
Errors
| Error | Example query |
|---|---|
ParseError.UnexpectedCharacter |
$.a b, $[?@.a = 1] |
ParseError.UnexpectedEnd |
$[0, $['a |
ParseError.InvalidUtf8 |
bytes that are not UTF-8 |
ParseError.UnpairedSurrogate |
a string with half of a surrogate pair |
ParseError.ControlCharacter |
a string literal with an unescaped tab character |
ParseError.InvalidEscape |
$['\a'] |
ParseError.InvalidInteger |
$[01], $[-0] |
ParseError.IntegerOutOfRange |
$[9007199254740992] |
ParseError.NumberOutOfRange |
$[?@ == 1e99999999999] |
ParseError.UnknownFunction |
$[?foo(@)] |
ParseError.WrongArgumentCount |
$[?length() == 1] |
ParseError.ArgumentTypeMismatch |
$[?count(1) == 1] |
ParseError.NonSingularQuery |
$[?@.* == 1], $[?length(@.*) == 1] |
ParseError.NotComparable |
$[?match(@, 'a') == true] |
ParseError.ValueTypeInTest |
$[?length(@)] |
ParseError.LiteralWithoutComparison |
$[?1], $[?true] |
ParseError.NestingTooDeep |
more than JsonPathParser.MAX_NESTING_DEPTH nested parentheses |
Positions
Each error has a position. For query text, the position is the index of a UTF-16 code
unit in the text. For UTF-8 bytes, ParseError.InvalidUtf8 gives the index of a byte; all other
errors give the index in the decoded text.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordAn argument does not agree with the declared type of its parameter (Section 2.4.3).static final recordA string literal contains an unescaped control character, U+0000 to U+001F (Section 2.3.1.1).static final recordAn index or a slice parameter is outside the I-JSON range (Section 2.1).static final recordA string literal contains an escape that is not permitted (Section 2.3.1.1).static final recordAn integer has a leading zero, or is-0where only an int is permitted.static final recordThe bytes are not well-formed UTF-8 (Section 2.1).static final recordA literal is a test expression.static final recordThe query has too many nested levels (Section 4.1).static final recordA query that is not singular is a side of a comparison, or a ValueType argument (Sections 2.3.5.1 and 2.4.3).static final recordA function with the result type LogicalType or NodesType is a side of a comparison (Section 2.4.3).static final recordA number literal has an exponent that is too large to represent.static final recordThe grammar does not permit the character at this position.static final recordThe query ends before it is complete.static final recordThe query calls a function that is not registered (Section 2.4).static final recordThe query contains an unpaired surrogate, or a backslash-u escape for one (Sections 1.1 and 2.3.1.1).static final recordA function with the result type ValueType is a test expression (Section 2.4.3).static final recordA function call has the wrong number of arguments (Section 2.4.3). -
Method Summary
-
Method Details
-
position
int position()Returns the position of the error.- Returns:
- the position of the error
-
message
Returns a description of the error.- Returns:
- a description of the error, with the position
-