-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add decoding from YamlNode #369
Add decoding from YamlNode #369
Conversation
Thanks for the contribution @dellisd. I'm wondering if this would be better suited as a method on Also, could you please add a test case for the scenario where the serializer is decoding something that isn't the root of the document? There might be an edge case there that I'd like to check. |
I agree adding a method to I can make these changes, and I'll add that test case. |
Expose current Yaml instance from YamlInput
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, just have a couple of questions...
@@ -32,49 +32,50 @@ import kotlinx.serialization.modules.SerializersModule | |||
@OptIn(ExperimentalSerializationApi::class) | |||
public sealed class YamlInput( | |||
public val node: YamlNode, | |||
public val yaml: Yaml, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this yaml: Yaml
property required? Is this so that custom deserializers can access it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's correct. I explained above that the Json implementations in kotlinx.serialization expose the Json
instances in the same way.
Thanks @dellisd! |
This adds a method on
YamlInput
that allows for decoding a serializable value from aYamlNode
.The use case for this kind of functionality is the ability to manually interpret the structure of a YAML document and then delegate the deserialization of
YamlNode
s to other serializer implementations.For example, in the test case I added we have this document:
which is a map of
Database
objects. Perhaps we want to decode this as aList<Database>
instead of aMap<String, Database>
(because reasons) and this enables us to write a custom serializer that looks at eachYamlNode
entry on theYamlMap
and then delegates the deserialization of eachDatabase
object to theDatabase
serializer rather than having to manually decode the rest of the Yaml structure.