/kaml

YAML support for kotlinx.serialization

Primary LanguageKotlinApache License 2.0Apache-2.0

kaml

Build Status Coverage License Maven Central

What is this?

This library adds YAML support to kotlinx.serialization.

YAML version 1.2 is supported.

Usage samples

Parsing from YAML to a Kotlin object

@Serializable
data class Team(
    val leader: String,
    val members: List<String>
)

val input = """
        leader: Amy
        members:
          - Bob
          - Cindy
          - Dan
    """.trimIndent()

val result = Yaml.default.parse(Team.serializer(), input)

println(result)

Serializing from a Kotlin object to YAML

@Serializable
data class Team(
    val leader: String,
    val members: List<String>
)

val input = Team("Amy", listOf("Bob", "Cindy", "Dan"))

val result = Yaml.default.stringify(Team.serializer(), input)

println(result)

Supported YAML features

Referencing kaml

Add the following to your Gradle build script:

implementation("com.charleskorn.kaml:kaml:<version number here>")

Check the releases page for the latest release information, and the Maven Central page for examples of how to reference the library in other build systems.

Contributing to kaml

Pull requests and bug reports are always welcome!

kaml uses batect to simplify development environment setup:

  • To build the library: ./batect build
  • To run the tests and static analysis tools: ./batect check
  • To run the tests and static analysis tools continuously: ./batect continuousCheck

Other commands are available by running ./batect --list-tasks

Reference links