Class JsonlTokenReader
- All Implemented Interfaces:
Closeable,AutoCloseable,RecordReader,TokenReader
TokenReader surface for the JSONL / NDJSON
format.
JSONL is a sequence of independent JSON values separated by newlines. There is no root
container. This cursor models that as a flat top-level sequence at depth 0:
each line's tokens are emitted in turn, and JsonTokenReader.next() returns TokenType.END_OF_STREAM
only when the underlying input is exhausted.
The most ergonomic way to consume a JSONL stream is via JsonTokenReader.read(Class), which binds one
line to a POJO per call:
Notes:
- This class is not thread safe.
- The cursor is a true O(1)-memory streaming cursor (
TokenReader.isStreaming()==true ).
-
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
ConstructorsConstructorDescriptionJsonlTokenReader(ParserPipe pipe) Constructor with default settings.JsonlTokenReader(ParserPipe pipe, JsonTokenReader.Settings settings, JsonlParserSession session) Constructor used byJsonlParserSession.readTokens(Object)to plumb the calling session through. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidSets the post-value state based on the enclosing container.Methods inherited from class org.apache.juneau.marshall.json.JsonTokenReader
allowsTrailingComma, canRead, close, getBinary, getBool, getCurrentToken, getDepth, getFieldName, getNumber, getNumberLexeme, getString, isDigit, isInArray, isNumberStart, next, parseException, popContainer, pushContainer, read, read, read, readCommaOrEndArray, readCommaOrEndObject, readFieldNameOrEndObject, readKeywordValue, readNumberValue, readSkipWsAndComments, readString, readValueStart, 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
-
JsonlTokenReader
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.
-
JsonlTokenReader
public JsonlTokenReader(ParserPipe pipe, JsonTokenReader.Settings settings, JsonlParserSession session) throws IOException Constructor used byJsonlParserSession.readTokens(Object)to plumb the calling session through.- Parameters:
pipe- The parser input pipe. Must not benull .settings- The cursor-level settings. Must not benull .session- TheJsonlParserSessionforJsonTokenReader.read(Class)delegation, ornull to disableread.- Throws:
IOException- If a problem occurred opening the underlying reader.
-
-
Method Details
-
afterValue
Description copied from class:JsonTokenReaderSets the post-value state based on the enclosing container.Subclasses (e.g. JsonlTokenReader) override this when the format treats consecutive top-level values differently — JSONL transitions back to
JsonTokenReader.S00_expectValueat depth 0 instead ofJsonTokenReader.S05_endso the next line is read.- Overrides:
afterValuein classJsonTokenReader
-