Class TomlParser

All Implemented Interfaces:
RecordReadable, TomlMetaProvider

public class TomlParser extends ReaderParser implements TomlMetaProvider, RecordReadable
Parses TOML v1.0.0 text into POJOs.

Handles Content-Type: application/toml

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 via convertAttrToType. Null keys are serialized as the string null and converted back to Java null during parsing.
  • Polymorphic types — Parsing to interfaces or abstract classes requires a bean dictionary when 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 to Duration via Iso8601Utils.
  • Year and YearMonth — Bare Year (4-digit integer) parses as Long, not Year. Use quoted strings (e.g. "2024") or yyyy-MM for YearMonth; swaps may be needed for full compatibility.
Example:

// Parse TOML into a JsonMap String toml = "name = \"myapp\"\nport = 8080"; JsonMap parsed = TomlParser.DEFAULT.read(toml, JsonMap.class); // Parse into a bean MyConfig config = TomlParser.DEFAULT.read(toml, MyConfig.class); // Parse into a parameterized type (e.g. Map with type args) Map<String, Object> map = TomlParser.DEFAULT.read(toml, Map.class, String.class, Object.class); // Use the marshaller for convenience parsed = Toml.to(toml, JsonMap.class);

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: