0.18.0
What's changed
-
New: kaml now supports working with polymorphic types where the type is specified as a
type
property in YAML (#11 - thanks to @gps for the suggestion).This means that there are now two styles available for working with polymorphic types (set
YamlConfiguration.polymorphismStyle
when creating an instance ofYaml
):-
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.stringify(Config.serializer(), config) println(result)
-
-
Updated: kaml is now built against Kotlin 1.3.72.
-
Changed: clearer exceptions will now be thrown in the following cases:
- missing tag when deserializing a polymorphic type when using tags for polymorphic type information
- unknown polymorphic type in tag or
type
property - missing required property for object
Upgrading
If you're using Gradle, reference kaml in your dependencies
block like this:
implementation("com.charleskorn.kaml:kaml:0.18.0")
For other tools, refer to the Maven Central release page for more information.