Class TomlParser
- All Implemented Interfaces:
RecordReadable,TomlMetaProvider
Handles
Limitations compared to JSON
TOML is a configuration format with a more restricted type system than JSON.
The following features supported by JsonParser
are not available or limited in TOML:
- Null values — TOML has no null type. Absent keys yield null for object properties.
The parser treats the configured
nullValue string (e.g.<NULL> ) as Java null when it appears as a value. - Non-string map keys — TOML keys are always strings. Non-string key types
(e.g.
Map<Integer,String> ) are converted viaconvertAttrToType. Null keys are serialized as the stringnull and converted back to Java null during parsing. - Polymorphic types — Parsing to interfaces or abstract classes requires a
bean dictionarywhen no_type discriminator is present in the document. - Duration — TOML has no native duration type. Quoted ISO-8601 duration strings
(e.g.
"PT1H30M" ) are parsed toDuration viaIso8601Utils. - Year and YearMonth — Bare
Year (4-digit integer) parses asLong , notYear . Use quoted strings (e.g."2024" ) oryyyy-MM forYearMonth ; swaps may be needed for full compatibility.
Example:
Example input (Map of name/age):
name = "Alice" age = 30
Complex (nested table + array):
name = "Alice" age = 30 tags = ["a", "b", "c"] [address] street = "123 Main St" city = "Boston" state = "MA"
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
FieldsModifier and TypeFieldDescriptionstatic final TomlParserDefault parser instance.protected final StringFields 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 TomlParser.Buildercreate()Creates a new builder.Create a session builder based on the properties defined on this context.Returns the string treated as null when parsing.Returns the TOML-specific metadata on the specified bean property.getTomlClassMeta(ClassMeta<?> cm) Returns the TOML-specific metadata on the specified class.booleanStreaming-quality signal queryable before opening a cursor.Returns the properties on this bean as a map for debugging.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, isReaderParserMethods 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 instance. -
nullValue
-
-
Constructor Details
-
TomlParser
Constructor.- Parameters:
builder- The builder.
-
-
Method Details
-
create
Creates a new builder.- Returns:
- A new builder.
-
getNullValue
Returns the string treated as null when parsing.- Returns:
- The null marker.
-
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.
-
getTomlBeanPropertyMeta
Description copied from interface:TomlMetaProviderReturns the TOML-specific metadata on the specified bean property.- Specified by:
getTomlBeanPropertyMetain interfaceTomlMetaProvider- Parameters:
bpm- The bean property to return the metadata on.- Returns:
- The metadata.
-
getTomlClassMeta
Description copied from interface:TomlMetaProviderReturns the TOML-specific metadata on the specified class.- Specified by:
getTomlClassMetain interfaceTomlMetaProvider- Parameters:
cm- The class to return the metadata on.- Returns:
- The metadata.
-
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.
-
properties
Description copied from class:ContextReturns the properties on this bean as a map for debugging.- Overrides:
propertiesin classReaderParser- Returns:
- The properties on this bean as a map for debugging.
-
readRecords
Convenience delegator that opens aRecordReaderover the input using default session arguments (mirrorsParser.read(Object, Class)).The real implementation lives on
TomlParserSession.readRecords(Object). Callers that need request-derived configuration (locale, timezone, schema, swaps) should callcreateSession()and invokeTomlParserSession.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.
-