Class TomlCodec
- All Implemented Interfaces:
Codec
The same audience as YAML — a message a person will read and edit — with the ambiguity
removed. TOML has one way to write a string, no significant indentation, and no Norway problem:
country = NO is a bare key error rather than a boolean that used to be a country. Where
a human edits the message and a machine acts on it, that matters more than terseness.
Reach for it for configuration broadcast to a fleet, feature flags, deployment instructions and anything replayed by hand from a dead-letter queue. It is a poor choice for high volume: it is text, it is larger than JSON, and it parses more slowly.
The shape of the data has to suit it. TOML is a table format, so a message body must be an object at the top level — a bare list or a bare number is not a TOML document and this codec will say so rather than inventing a wrapper. Deep nesting reads poorly too; where the payload is a tree rather than a table, JSON is the honest answer.
Like the YAML codec, this one never volunteers for a message whose sender set no content type. Guessing wrong here would record a TOML message arriving where a JSON one did.
-
Constructor Details
-
TomlCodec
public TomlCodec()Uses a mapper that ignores unknown keys and writes dates as text. -
TomlCodec
public TomlCodec(com.fasterxml.jackson.databind.ObjectMapper mapper) - Parameters:
mapper- the mapper to use; it must be built on aTomlFactory, or this codec will announce TOML and write something else
-
-
Method Details
-
defaultMapper
public static com.fasterxml.jackson.databind.ObjectMapper defaultMapper()- Returns:
- a mapper that tolerates keys it does not know and writes readable timestamps
-
contentType
- Specified by:
contentTypein interfaceCodec- Returns:
- the content type this codec produces, for example
application/json
-
encode
-
decode
-
canDecode
-
toString
-