Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

net.mamoe.yamlkt:yamlkt-watchosArm32

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

net.mamoe.yamlkt:yamlkt-watchosArm32

Multiplatform YAML parser & serializer for kotlinx.serialization written in pure Kotlin.

  • 0.10.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

YamlKt

Gradle CI Download

Fast multi-platform YAML with comments support for kotlinx.serialization

This project is in alpha state.

Setup

Third-party formats for kotlinx.serialization is strongly dependent on the versions of kotlinx-serialization-core and Kotlin compiler.

yamlktKotlinkotlinx-serialization-core
0.3.31.3.700.20.0
0.5.31.4.01.0.0-RC
0.6.01.4.101.0.0-RC2
0.8.01.4.101.0.1
0.9.01.4.301.1.0-RC
0.10.01.5.201.2.1
Gradle
repositories {
  mavenCentral()
}
dependencies {
    implementation("net.mamoe.yamlkt:yamlkt:0.10.0")
}

If your project is multiplatform, you need only to add this dependency for commonMain.

Maven

Only JVM target is available for Maven.

<dependency>
    <groupId>net.mamoe.yamlkt</groupId>
    <artifactId>yamlkt-jvm</artifactId>
    <version>0.10.0</version>
</dependency>

Overview

This library supports:

  • fast deserializing YAML text to a structured object
  • contextual and polymorphic serialization: @Contextual, @Polymorphic
  • dynamic types: YamlDynamicSerializer which works on Any
  • YamlElement wrapper classes, allowing YamlMap.getInt, YamlMap.getLong
  • comments encoding (Using annotation Comment)

The features that aren't yet supported:

  • Anchors (*, &)
  • Explicit types (e.g. !!map)
  • Multiline string (|, >, \)

Learn to use

Serialize / deserialize with compiled serializers

This approach is fastest and recommended way as the type is already provided.

@Serializable
data class Test(
    val test: String,
    val optional: String = "optional", // Having default value means optional
    val nest: Nested,
    val list: List<String>
) {
    @Serializable
    data class Nested(
        val numberCast: Int
    )
}

println(Yaml.parse(Test.serializer(), """
test: testString
nest: 
  numberCast: 0xFE
list: [str, "str2"]
"""))
Contextual serializing / deserializing

YamlKt provides a contextual serializer YamlDynamicSerializer for Any
and YamlNullDynamicSerializer for Any?

By default, YamlDynamicSerializer is installed to Any.
You can start by using @Contextual:

@Serializable
data class Test(
    val any: @Contextual Any
)

Yaml.parse(Test.serializer(), yamlText)

For input YAML text:

test: { key1: v1, key2: [v2, v3, v4] }

Alternatively, you can deserialize without any class:

val map: Map<String?, Any?> = Yaml.parseMap("""test: { key1: v1, key2: [v2, v3, v4] }""")
YamlElement

YamlElement is a type-safe way to deserialize without descriptors.

val map: YamlMap = Yaml.decodeYamlMapFromString("""test: { key1: v1, key2: [v2, v3, v4] }""")
Comments

Annotate your comments to a field(property) using @Comment:
Example:

@Serializable
data class User(
  @Comment("The name of the user")
  val name: String = "value"
)

gives yaml text:

# The name of the user
name: ""

FAQs

Package last updated on 01 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc