kaml icon indicating copy to clipboard operation
kaml copied to clipboard

Support for YAML transformations like there is for JSON

Open Vampire opened this issue 3 years ago • 7 comments

I've just read https://github.com/Kotlin/kotlinx.serialization/blob/v0.20.0/docs/json_transformations.md and really like that. But I need that for YAML. If you want to deserialize a GitHub action definition file, you have for example exactly the use-case of polymorphism by shape. Would be really cool if kaml would also have such functionality built-in.

(Don't wonder that I'm reading the 0.20.0 docs, I'm using this in a Gradle build and therefore I cannot use 1.4.0 yet)

Vampire avatar Aug 20 '20 17:08 Vampire

Hey @Vampire, this functionality isn't built in to kaml. If you'd be interested in adding it with a PR, I'd be happy to talk about possible solutions.

In the meantime, you can do something similar by implementing a custom serializer that casts the decoder to a YamlInput and inspects the node property. https://github.com/batect/batect/blob/master/app/src/main/kotlin/batect/config/io/deserializers/StringOrObjectSerializer.kt#L50 is an example of this technique - it looks at the node type to determine whether it is a string or an object.

charleskorn avatar Aug 22 '20 01:08 charleskorn

I'm sorry, I'm right now too occupied with other contributions and actually I know the files I want to deserialize / serialize, so for now I just can live without the shape-based polymorphism. Maybe I find some time later or maybe you find time yourself in the meantime. :-)

Vampire avatar Aug 22 '20 19:08 Vampire

This issue has been automatically marked as stale because it has not had any activity in the last 60 days. It will automatically be closed if no further activity occurs in the next seven days to enable maintainers to focus on the most important issues. If this issue is still affecting you, please comment below within the next seven days. Thank you for your contributions.

stale[bot] avatar Jul 07 '22 09:07 stale[bot]

This issue has been automatically marked as stale because it has not had any activity in the last 60 days. It will automatically be closed if no further activity occurs in the next seven days to enable maintainers to focus on the most important issues. If this issue is still affecting you, please comment below within the next seven days. Thank you for your contributions.

stale[bot] avatar Sep 05 '22 16:09 stale[bot]

This issue has been automatically marked as stale because it has not had any activity in the last 60 days. It will automatically be closed if no further activity occurs in the next seven days to enable maintainers to focus on the most important issues. If this issue is still affecting you, please comment below within the next seven days. Thank you for your contributions.

stale[bot] avatar Nov 04 '22 17:11 stale[bot]

This issue has been automatically closed because it has not had any recent activity.

stale[bot] avatar Nov 11 '22 18:11 stale[bot]

This is not implemented, is it? Please reopen.

Vampire avatar Nov 21 '22 02:11 Vampire