Class JsonlParser
- All Implemented Interfaces:
JsonMetaProvider,ArrayRecordReadable,RecordReadable,TokenReadable
Media types
Handles
Description
Parses JSONL input where each non-empty line is a complete JSON value. Blank lines are ignored. The conversion is as follows...
- JSON objects (
{...} ) are converted toJsonMapsor Java beans if a target type is provided. - JSON arrays (
[...] ) are converted toJsonLists. - JSON strings are converted to
Strings. - JSON numbers are converted to
Integers,Longs,Floats, orDoubles. - JSON booleans are converted to
Booleans. - JSON nulls are converted to
null .
When the target type is a Collection or array, each line is parsed
as one element. When the target type is a single value, only the first non-empty line is parsed.
Example:
Example input:
{"name":"Alice","age":30} {"name":"Bob","age":25} {"name":"Carol","age":35}
Limitations compared to JSON
- No multi-line JSON input: Each JSON value must be on a single line. Multi-line (pretty-printed) JSON piped as JSONL input will cause parse errors.
- First-line-only for non-collection targets: When parsing JSONL to a single non-collection type, only the first non-empty line is parsed; trailing lines are silently ignored.
Notes:
- This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.juneau.marshall.json.JsonParser
JsonParser.Builder<SELF extends JsonParser.Builder<SELF>>Nested classes/interfaces inherited from class org.apache.juneau.marshall.parser.ReaderParser
ReaderParser.DefaultBuilderNested classes/interfaces inherited from class org.apache.juneau.marshall.parser.Parser
Parser.Null -
Field Summary
FieldsFields inherited from class org.apache.juneau.marshall.json.JsonParser
validateEndFields inherited from class org.apache.juneau.marshall.parser.Parser
autoCloseStreams, consumes, debugOutputLines, listener, nulls, trimStrings, unbufferedFields inherited from class org.apache.juneau.marshall.MarshallingContextable
marshallingContextFields inherited from class org.apache.juneau.marshall.Context
CONTEXT_APPLY_FILTER -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonParser.Builder<?>create()Creates a new builder for this object.Create a session builder based on the properties defined on this context.Methods inherited from class org.apache.juneau.marshall.json.JsonParser
copy, getJsonBeanPropertyMeta, getJsonClassMeta, getSession, isValidateEnd, readArrayRecords, readTokensMethods inherited from class org.apache.juneau.marshall.parser.ReaderParser
getStreamCharset, isReaderParser, propertiesMethods inherited from class org.apache.juneau.marshall.parser.Parser
canHandle, createParserBuilder, doRead, getDebugOutputLines, getListener, getMediaTypes, getNulls, getPrimaryMediaType, isAutoCloseStreams, isTrimStrings, isUnbuffered, read, read, read, read, read, read, readArgs, readIntoCollection, readIntoMap, readWithOuterMethods inherited from class org.apache.juneau.marshall.MarshallingContextable
getDurationFormat, getMarshallingContext, getPeriodFormatMethods inherited from class org.apache.juneau.marshall.Context
createBuilder, getAnnotationProvider, init, isDebug, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.marshall.stream.ArrayRecordReadable
isArrayRecordStreaming, readArrayRecordsMethods inherited from interface org.apache.juneau.marshall.stream.RecordReadable
isRecordStreamingMethods inherited from interface org.apache.juneau.marshall.stream.TokenReadable
readRecords
-
Field Details
-
DEFAULT
Default parser.
-
-
Constructor Details
-
JsonlParser
Constructor.- Parameters:
builder- The builder for this object.
-
-
Method Details
-
create
Creates a new builder for this object.- Returns:
- A new builder.
-
createSession
Description copied from class:ContextCreate a session builder based on the properties defined on this context.Use this method for creating sessions where you want to override basic settings. Otherwise, use
Context.getSession()directly.- Overrides:
createSessionin classJsonParser- Returns:
- A new session builder.
-