-
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: add map_all for xml mapping #129
Conversation
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.
@HassanAkbar looks good! Could you please help document this in the README with an example? Thanks.
@HassanAkbar what happens with map_all when the format is JSON? Does this mean that a class that uses map_all cannot do JSON etc? |
@ronaldtse Yes this PR only adds person = {
name: "test",
age: "20",
description: { title: "foobar", awards: "many" }
}.to_json
class Person < Lutaml::Model::Serializable
attribute :name, :string
attribute :age, :integer
attribute :description, :string
json do
map "name", to: :name
map "age", to: :age
map "description", to: :description
end
end
Person.from_json(person)
#<Person:0x00000001044dd9b0
@age=20,
@description="{\"title\"=>\"foobar\", \"awards\"=>\"many\"}",
@name="test",
@using_default={:name=>false, :age=>false, :description=>false},
@validate_on_set=false> I will open a separate PR for |
I think what I don't understand is, how does the concept of JSON is like: YAML is like: Does <element>
<one>text</one>
</element>
<element attr=1>
<one>text</one>
</element>
<one>text</one> |
@ronaldtse the
|
Added
map_all
for mapping all content inside an XML tag to an attribute.fixes #57
can be used for -> #106