-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: added root_mappings option #222
Conversation
Instead of calling it Because the |
a2a8de2
to
0cb1be9
Compare
@HassanAkbar the feature is not fully functional yet. I've provided new examples in the README and they are supposed to work (I believe). For example the simplest example:
|
@HassanAkbar can you please help go through the 3 examples I provided in the README and add them as Specs? Thanks. |
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.
Need fixing...
6287b78
to
63504ae
Compare
63504ae
to
594fa0a
Compare
@ronaldtse All the examples that you have added are passing except the last one which is # This is Lutaml::Model class that represents the collection of Ceramic objects
class CeramicCollection < Lutaml::Model::Serializable
attribute :ceramics, Ceramic, collection: true
key_value do
map to: :ceramics, # All data goes to the `ceramics` attribute
root_mappings: {
# The key of an object in this collection is mapped to the ceramic_id
# attribute of the Ceramic object.
key: :ceramic_id # "key" is a reserved keyword
}
end
end
> new_collection = CeramicCollection.new(ceramics: [
Ceramic.new(ceramic_id: "vase1", ceramic_name: "Imperial Vase"),
Ceramic.new(ceramic_id: "bowl2", ceramic_name: "18th Century Bowl")
])
> puts new_collection.to_yaml Expected Output: # ---
# vase1:
# name: Imperial Vase
# bowl2:
# name: 18th Century Bowl Actual Output: # vase1:
# bowl2: This is happening because we are using the I think this is the correct behavior because we don't know how to handle |
@HassanAkbar sorry it seems that my changes to the README somehow disappeared. I have pushed some README changes that adopted the approach from our discussion for attribute mapping, i.e.
Please have a look and let me know if it works. Thanks! |
Thank you @HassanAkbar ! This is now merged. |
Added support for root mappings. It allows the
key-value
pair with a dynamic name. The values are extracted from thekey-value
data model using the root key value.Other mappings like
map_element
can't be defined withroot_mappings
.closes #216