All Projects → charleskorn → Kaml

charleskorn / Kaml

Licence: apache-2.0
YAML support for kotlinx.serialization

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kaml

Chronicle Wire
A Java Serialisation Library that supports multiple formats
Stars: ✭ 204 (+14.61%)
Mutual labels:  yaml, serialization
crystalizer
(De)serialize any Crystal object - out of the box. Supports JSON, YAML and Byte format.
Stars: ✭ 32 (-82.02%)
Mutual labels:  yaml, serialization
Mashumaro
Fast and well tested serialization framework on top of dataclasses
Stars: ✭ 208 (+16.85%)
Mutual labels:  yaml, serialization
Thorsserializer
C++ Serialization library for JSON
Stars: ✭ 241 (+35.39%)
Mutual labels:  yaml, serialization
Mini Yaml
Single header YAML 1.0 C++11 serializer/deserializer.
Stars: ✭ 79 (-55.62%)
Mutual labels:  yaml, serialization
Rapidyaml
Rapid YAML - a library to parse and emit YAML, and do it fast.
Stars: ✭ 183 (+2.81%)
Mutual labels:  yaml, serialization
coqpit
Simple but maybe too simple config management through python data classes. We use it for machine learning.
Stars: ✭ 67 (-62.36%)
Mutual labels:  yaml, serialization
Srsly
🦉 Modern high-performance serialization utilities for Python (JSON, MessagePack, Pickle)
Stars: ✭ 189 (+6.18%)
Mutual labels:  yaml, serialization
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+369.66%)
Mutual labels:  yaml, serialization
Simple-YAML
A Java API that provides an easy-to-use way to store data using the YAML format.
Stars: ✭ 68 (-61.8%)
Mutual labels:  yaml, serialization
dataconf
Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.
Stars: ✭ 40 (-77.53%)
Mutual labels:  yaml, serialization
Pretty Yaml
PyYAML-based module to produce pretty and readable YAML-serialized data
Stars: ✭ 110 (-38.2%)
Mutual labels:  yaml, serialization
Yamldotnet
YamlDotNet is a .NET library for YAML
Stars: ✭ 1,382 (+676.4%)
Mutual labels:  yaml, serialization
Datafiles
A file-based ORM for Python dataclasses.
Stars: ✭ 113 (-36.52%)
Mutual labels:  yaml, serialization
Netstack
Lightweight toolset for creating concurrent networking systems for multiplayer games
Stars: ✭ 157 (-11.8%)
Mutual labels:  serialization
Rcc
RCC is a set of tooling that allows you to create, manage, and distribute Python-based self-contained automation packages - or 'robots' as we call them.
Stars: ✭ 168 (-5.62%)
Mutual labels:  yaml
K8ssandra
K8ssandra is an open-source distribution of Apache Cassandra for Kubernetes including API services and operational tooling.
Stars: ✭ 155 (-12.92%)
Mutual labels:  yaml
Feedparser
feedparser gem - (universal) web feed parser and normalizer (XML w/ Atom or RSS, JSON Feed, HTML w/ Microformats e.g. h-entry/h-feed or Feed.HTML, Feed.TXT w/ YAML, JSON or INI & Markdown, etc.)
Stars: ✭ 156 (-12.36%)
Mutual labels:  yaml
Deploy
Ansible role to deploy scripting applications like PHP, Python, Ruby, etc. in a capistrano style
Stars: ✭ 2,141 (+1102.81%)
Mutual labels:  yaml
Models
WordPress plugin to create custom post types and taxonomies using JSON, YAML or PHP files
Stars: ✭ 167 (-6.18%)
Mutual labels:  yaml

kaml

Pipeline 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.decodeFromString(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.encodeToString(Team.serializer(), input)

println(result)

Referencing kaml

Add the following to your Gradle build script:

Groovy DSL

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.4.20'
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.4.20'
}

dependencies {
  implementation "com.charleskorn.kaml:kaml:<version number here>" // Get the latest version number from https://github.com/charleskorn/kaml/releases/latest
}

Kotlin DSL

plugins {
    kotlin("jvm") version "1.4.20"
    kotlin("plugin.serialization") version "1.4.20"
}

dependencies {
  implementation("com.charleskorn.kaml:kaml:<version number here>") // Get the latest version number from https://github.com/charleskorn/kaml/releases/latest
}

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.

Features

  • Supports most major YAML features:

  • Supports parsing YAML to Kotlin objects (deserializing) and writing Kotlin objects as YAML (serializing)

  • Supports kotlinx.serialization's polymorphism for sealed and unsealed types

    Two styles are available (set YamlConfiguration.polymorphismStyle when creating an instance of Yaml):

    • using YAML tags to specify the type:

      servers:
        - !<frontend>
          hostname: a.mycompany.com
        - !<backend>
          database: db-1
      
    • using a type property to specify the type:

      servers:
        - type: frontend
          hostname: a.mycompany.com
        - type: backend
          database: db-1
      

    The fragments above could be generated with:

    @Serializable
    sealed class Server {
      @SerialName("frontend")
      @Serializable
      data class Frontend(val hostname: String)
    
      @SerialName("backend")
      @Serializable
      data class Backend(val database: String)
    }
    
    @Serializable
    data class Config(val servers: List<Server>)
    
    val config = Config(listOf(
      Frontend("a.mycompany.com"),
      Backend("db-1")
    ))
    
    val result = Yaml.default.encodeToString(Config.serializer(), config)
    
    println(result)
    
  • Supports Docker Compose-style extension fields

    x-common-labels: &common-labels
      labels:
        owned-by: [email protected]
        cost-centre: myteam
    
    servers:
      server-a:
        <<: *common-labels
        kind: frontend
    
      server-b:
        <<: *common-labels
        kind: backend
    
      # server-b and server-c are equivalent
      server-c:
        labels:
          owned-by: [email protected]
          cost-centre: myteam
        kind: backend
    

    Specify the extension prefix by setting YamlConfiguration.extensionDefinitionPrefix when creating an instance of Yaml (eg. "x-" for the example above).

    Extensions can only be defined at the top level of a document, and only if the top level element is a map or object. Any key starting with the extension prefix must have an anchor defined (&...) and will not be included in the deserialised value.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].