Class Json5TokenReader
- All Implemented Interfaces:
Closeable,AutoCloseable,RecordReader,TokenReader
- Direct Known Subclasses:
Json5lTokenReader
TokenReader surface for the JSON5 format.
Subclasses JsonTokenReader to add the JSON5 dialect's relaxations:
- Strings can be single-quoted, double-quoted, or unquoted bare identifiers.
- Field names can be single-quoted, double-quoted, or unquoted bare identifiers.
- Trailing commas before
] /} are allowed. - Missing values in arrays / objects emit
TokenType.VALUE_NULL. - JavaScript comments (
// line,/* */ block) are tolerated — already accepted by the parent class. - JSON5 numbers: leading
+ , leading/trailing decimal points, hexadecimal,Infinity/NaN. - String line-continuation (backslash + line terminator is omitted from the value).
The cursor is a true O(1)-memory streaming cursor (TokenReader.isStreaming() ==
Notes:
- This class is not thread safe.
- The cursor is purely structural; object swaps and
@Schemaannotations have no effect. Use the POJO databind path onJson5Parserfor those.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.marshall.json.JsonTokenReader
JsonTokenReader.Settings -
Field Summary
Fields inherited from class org.apache.juneau.marshall.json.JsonTokenReader
currentBoolean, currentFieldName, currentNumberLexeme, currentString, currentToken, depth, r, S00_expectValue, S01_expectFieldName, S02_expectColon, S03_expectCommaOrEndObject, S04_expectCommaOrEndArray, S05_end, settings, stateFields inherited from interface org.apache.juneau.marshall.stream.TokenReader
MSG_READ_NON_VALUE_STATE -
Constructor Summary
ConstructorsConstructorDescriptionJson5TokenReader(ParserPipe pipe) Constructor with default settings.Json5TokenReader(ParserPipe pipe, JsonTokenReader.Settings settings, Json5ParserSession session) Constructor used byJson5ParserSession.readTokens(Object)to plumb the calling session through so thatJsonTokenReader.read(Class)can delegate to the JSON5 databind path. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanSubclass extension point: returns whether trailing commas are accepted before] /} .Returns the current numeric value as a parsedNumber.protected voidreadCommaOrEndArray(int c) State-machine dispatch: handles the next character atJsonTokenReader.S04_expectCommaOrEndArray.protected voidreadCommaOrEndObject(int c) State-machine dispatch: handles the next character atJsonTokenReader.S03_expectCommaOrEndObject.protected voidreadFieldNameOrEndObject(int c) State-machine dispatch: handles the next character atJsonTokenReader.S01_expectFieldName.protected voidReads a JSON number from the current input position.protected StringReads a double-quoted JSON string from the current input position.protected voidreadValueStart(int c) State-machine dispatch: handles the next character atJsonTokenReader.S00_expectValue.Methods inherited from class org.apache.juneau.marshall.json.JsonTokenReader
afterValue, canRead, close, getBinary, getBool, getCurrentToken, getDepth, getFieldName, getNumberLexeme, getString, isDigit, isInArray, isNumberStart, next, parseException, popContainer, pushContainer, read, read, read, readKeywordValue, readSkipWsAndComments, skipChildrenMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.juneau.marshall.stream.RecordReader
iterator, streamMethods inherited from interface org.apache.juneau.marshall.stream.TokenReader
getExtType, getNativeKind, getSimpleValue, getTag, getTagCount, isStreaming
-
Constructor Details
-
Json5TokenReader
Constructor with default settings.- Parameters:
pipe- The parser input pipe to read from. Must not benull .- Throws:
IOException- If a problem occurred opening the underlying reader.
-
Json5TokenReader
public Json5TokenReader(ParserPipe pipe, JsonTokenReader.Settings settings, Json5ParserSession session) throws IOException Constructor used byJson5ParserSession.readTokens(Object)to plumb the calling session through so thatJsonTokenReader.read(Class)can delegate to the JSON5 databind path.- Parameters:
pipe- The parser input pipe to read from. Must not benull .settings- The cursor-level settings. Must not benull .session- TheJson5ParserSessionforJsonTokenReader.read(Class)delegation, ornull to disableread.- Throws:
IOException- If a problem occurred opening the underlying reader.
-
-
Method Details
-
allowsTrailingComma
Description copied from class:JsonTokenReaderSubclass extension point: returns whether trailing commas are accepted before] /} .Default returns
false (strict RFC-8259 JSON). Json5TokenReader overrides this to returntrue for the JSON5 dialect.- Overrides:
allowsTrailingCommain classJsonTokenReader- Returns:
true if a trailing comma should be silently accepted;false if it should produce a parse error.
-
readNumberValue
Description copied from class:JsonTokenReaderReads a JSON number from the current input position. Captures the lexeme viaParserReader.readNumberString()and validates it; defers actual numeric parsing toJsonTokenReader.getNumber()(lazy). SetsJsonTokenReader.currentNumberLexemeandJsonTokenReader.currentToken.- Overrides:
readNumberValuein classJsonTokenReader- Throws:
IOException- If a problem occurred reading from the underlying stream.ParseException- If the input is not a valid JSON number.
-
getNumber
Description copied from interface:TokenReaderReturns the current numeric value as a parsedNumber.Implementations may parse lazily; the returned
Numbersubtype is implementation- and format-defined (e.g.Long/Double/BigDecimal). UseTokenReader.getNumberLexeme()to recover the original textual form.- Specified by:
getNumberin interfaceTokenReader- Overrides:
getNumberin classJsonTokenReader- Returns:
- The parsed numeric value.
- Throws:
ParseException- If the lexeme cannot be parsed.
-
readValueStart
Description copied from class:JsonTokenReaderState-machine dispatch: handles the next character atJsonTokenReader.S00_expectValue.Subclasses (e.g. Json5TokenReader) override this to add dialect-specific value shapes (single-quoted strings, bare identifiers, missing-value handling).
- Overrides:
readValueStartin classJsonTokenReader- Parameters:
c- The next non-whitespace, non-comment character read from the input.- Throws:
IOException- If a problem occurred reading from the underlying stream.ParseException- If the input is malformed at this position.
-
readFieldNameOrEndObject
Description copied from class:JsonTokenReaderState-machine dispatch: handles the next character atJsonTokenReader.S01_expectFieldName.Subclasses (e.g. Json5TokenReader) override this to accept bare-identifier field names and single-quoted field names.
- Overrides:
readFieldNameOrEndObjectin classJsonTokenReader- Parameters:
c- The next non-whitespace character read from the input.- Throws:
IOException- If a problem occurred reading from the underlying stream.ParseException- If the input is malformed at this position.
-
readCommaOrEndArray
Description copied from class:JsonTokenReaderState-machine dispatch: handles the next character atJsonTokenReader.S04_expectCommaOrEndArray.Subclasses (e.g. Json5TokenReader) override this to accept trailing commas before
] .- Overrides:
readCommaOrEndArrayin classJsonTokenReader- Parameters:
c- The next non-whitespace character read from the input.- Throws:
IOException- If a problem occurred reading from the underlying stream.ParseException- If the input is malformed at this position.
-
readCommaOrEndObject
Description copied from class:JsonTokenReaderState-machine dispatch: handles the next character atJsonTokenReader.S03_expectCommaOrEndObject.Subclasses (e.g. Json5TokenReader) override this to accept trailing commas before
} .- Overrides:
readCommaOrEndObjectin classJsonTokenReader- Parameters:
c- The next non-whitespace character read from the input.- Throws:
IOException- If a problem occurred reading from the underlying stream.ParseException- If the input is malformed at this position.
-
readString
Description copied from class:JsonTokenReaderReads a double-quoted JSON string from the current input position.Handles escape sequences (
\\n ,\\t ,\\uNNNN , etc.) inline viaParserReader.replace(char). Subclasses (e.g. Json5TokenReader) override this to also accept single-quoted strings.- Overrides:
readStringin classJsonTokenReader- Returns:
- The parsed string (without surrounding quotes).
- Throws:
IOException- If a problem occurred reading from the underlying stream.ParseException- If the input is malformed at this position.
-