YamlReader

object YamlReader

Thin wrapper around SnakeYAML that reads YAML content into a Map<String, Any?> suitable for consumption by the Deserializer.

SnakeYAML automatically resolves YAML scalars to their natural JVM types (Int, Double, Boolean, String, etc.) and nested mappings to LinkedHashMap instances. This object re-uses a single Yaml parser instance, which is safe because SnakeYAML parsers are stateless after construction.

Usage from a file:

val map = YamlReader.read(File("config.yml"))
val config = deserializer.deserialize(MyConfig::class, map, errors)

Usage from a raw string (useful in tests):

val yaml = """
server:
port: 8080
""".trimIndent()
val map = YamlReader.readString(yaml)

Since

1.0

See also

Functions

Link copied to clipboard
fun read(file: File): Map<String, Any?>

Reads and parses a YAML file into a flat/nested map.

Link copied to clipboard
fun readString(content: String): Map<String, Any?>

Parses a YAML string directly into a flat/nested map.