-
Notifications
You must be signed in to change notification settings - Fork 3
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
Serializable
implementation
#2
Comments
I'd love to implement this. However, KDL is a bit more complex than JSON or YAML, and will require some work designing an adequate Serializable syntax. I'd love to hear any idea you have, perhaps show some examples as to how you would use it. I'm thinking of getting inspiration from knus which does a similar thing in Rust. In the meantime, I've added a |
First of all, thank you very much!! That is fantastic already. Since creating this issue I've spent some more time with KDL and I've come to realise that it's more akin to XML than YAML or JSON, so full I'll play around with the builder and report back! Thanks a lot!! |
I've started working on an implementation here: #6 Struggling a bit to get it to work. Any assistance would be much appreciated 🙏🏻 |
I looked into it a bit more in the past days, and I think there are a few things to consider regarding the possible API. Some of the things to note:
Currently, the builder can output comments for
KDL document
and the corresponding Crystal code class Info
include KDL::Serializable
@[KDL::Field(key: "Collected-Pokemon")]
property pokemon : CollectedPokemon
property trainers : KDL::Node
end
class CollectedPokemon < KDL::Node
include KDL::Serializable
@[KDL::Field(key: "Snorlax")]
property snorlax : Pokemon
# It could also be possible to define a new `children` instance variable to serialize as a custom type
property list : Array(Pokemon)
end
class Pokemon < KDL::Node
include KDL::Serializable
@[KDL::Field(key: "pokemon-level")]
property level : KDL::Property
property status : KDL::Property
end
# Then, one could call
info = Info.from_kdl (parsed_kdl_doc_here)
info.pokemon.snorlax.status # => "asleep"
info.pokemon.children # => Array(KDL::Node)
info.pokemon.list # => Array(Pokemon) This would be relatively close to how However, there's another issue with regards to deserialisation, in addition to Take the following excerpt of the Niri compositor config:
This uses node names themselves as the actual information. https://kdl.dev/ mentions that for lists like this, it's convention to name the nodes
What do you think? |
I've got an initial working solution now on #6 One thing I haven't done yet is using
|
Hi!
Thanks for the shard! I just came across KDL recently, and it looks fantastic! Unlike YAML, it also seems to support comments, which very cool and has been a big wish of mine.
Is there any chance we could get a
Serializable
implementation for KDL to read to and save from Crystal structs / classes? (I have 0 idea how feasible this is, but I figured I'd still ask :D)Thanks in advance!
The text was updated successfully, but these errors were encountered: