Class HjsonParser
- All Implemented Interfaces:
HjsonMetaProvider,RecordReadable
Media types
Handles
Description
This parser handles all standard Hjson syntax as defined by the Hjson specification.
In addition to standard JSON, this parser handles the following:
-
#single-line comments (to end of line). -
//single-line comments. -
/* ... */block comments. - Quoteless string values (text read to end of line, leading/trailing whitespace trimmed).
-
Multiline strings delimited by
'''(triple single-quote) with indentation stripping. - Optional commas — newlines may serve as member/element separators.
- Trailing commas (ignored).
- Unquoted keys.
-
Root-braceless objects (top-level content without wrapping
{}).
Value type disambiguation: the parser identifies value types in this order:
number → boolean → null → quoteless string.
A value such as 5 times that starts like a number but contains non-numeric
characters is treated as a quoteless string.
This parser handles the following input and returns the corresponding Java type:
-
Hjson/JSON objects (
{...}) are converted toJsonMaps. Note: If aattribute is specified on the object, an attempt is made to convert the object to an instance of the specified Java bean class._type ='xxx' -
Hjson/JSON arrays (
[...]) are converted toJsonLists. -
Quoted strings (
"..."or'...') are converted toStrings. -
Multiline strings (
'''...''') are converted toStrings. -
Quoteless strings are converted to
Strings. -
Numbers are converted to
Integers,Longs,Floats, orDoublesdepending on size and format. -
true/falseare converted toBooleans. -
nullreturnsnull . -
Input consisting of only whitespace or comments returns
null .
Example input - readable mode:
{ name: Alice age: 30 }
Example input - compact mode:
{name:Alice,age:30}
Notes:
- Root-braceless Hjson files (content without a wrapping
{}) are supported on input, butHjsonSerializeralways emits root braces by default. A parse-then-serialize round-trip of a root-braceless file will produce braced output. - This class is thread safe and reusable.
See Also:
-
Nested Class Summary
Nested ClassesNested 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.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 TypeMethodDescriptioncopy()Creates a builder from this context object.static HjsonParser.Buildercreate()Creates a new builder.Create a session builder based on the properties defined on this context.Returns the Hjson-specific metadata on the specified bean property.getHjsonClassMeta(ClassMeta<?> cm) Returns the Hjson-specific metadata on the specified class.booleanStreaming-quality signal queryable before opening a cursor.readRecords(Object input) Convenience delegator that opens aRecordReaderover the input using default session arguments (mirrorsParser.read(Object, Class)).Methods inherited from class org.apache.juneau.marshall.parser.ReaderParser
getSession, 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, toString
-
Field Details
-
DEFAULT
Default parser.
-
-
Constructor Details
-
HjsonParser
Constructor.- Parameters:
builder- The builder.
-
-
Method Details
-
create
Creates a new builder.- 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 classReaderParser- Returns:
- A new session builder.
-
copy
Description copied from class:ContextCreates a builder from this context object.Builders are used to define new contexts (e.g. serializers, parsers) based on existing configurations.
-
getHjsonBeanPropertyMeta
Description copied from interface:HjsonMetaProviderReturns the Hjson-specific metadata on the specified bean property.- Specified by:
getHjsonBeanPropertyMetain interfaceHjsonMetaProvider- Parameters:
bpm- The bean property to return the metadata on.- Returns:
- The metadata.
-
getHjsonClassMeta
Description copied from interface:HjsonMetaProviderReturns the Hjson-specific metadata on the specified class.- Specified by:
getHjsonClassMetain interfaceHjsonMetaProvider- Parameters:
cm- The class to return the metadata on.- Returns:
- The metadata.
-
readRecords
Convenience delegator that opens aRecordReaderover the input using default session arguments (mirrorsParser.read(Object, Class)).The real implementation lives on
HjsonParserSession.readRecords(Object). Callers that need request-derived configuration (locale, timezone, schema, swaps) should callcreateSession()and invokeHjsonParserSession.readRecords(Object)on the built session instead.- Specified by:
readRecordsin interfaceRecordReadable- Parameters:
input- The input.- Returns:
- A new
RecordReadercursor. - Throws:
IOException- If a problem occurred opening the underlying input.
-
isRecordStreaming
Description copied from interface:RecordReadableStreaming-quality signal queryable before opening a cursor.- Specified by:
isRecordStreamingin interfaceRecordReadable- Returns:
true ifRecordReadable.readRecords(Object)returns an O(1)-memory streaming cursor;false for buffered (whole-value) formats backed byRecordAdapter.
-