Yaml Writer
object YamlWriter
Writes serialized configuration data to YAML format with comment support.
This writer produces clean, human-readable YAML output and supports two comment placement modes:
CommentPlacement.INLINE: Single-line comments are placed on the same line as the value (e.g.,
port: 8080 # The server port). Falls back to ABOVE placement for multi-line comments, lists, and map sections.CommentPlacement.ABOVE: Comments are placed on separate lines above the property. An empty line is inserted before section-level comments for readability.
Scalar values are automatically quoted when they contain special YAML characters (:, #, {, }, etc.), look like booleans (true/false), nulls, or numbers.
Example:
val data = mapOf("server" to mapOf("port" to 8080, "host" to "localhost"))
val comments = mapOf("server.port" to CommentData(listOf("The server port"), CommentPlacement.INLINE))
YamlWriter.write(File("config.yml"), data, comments)
// Produces:
// server:
// port: 8080 # The server port
// host: localhostContent copied to clipboard
Since
1.0