Closed andrew2net closed 1 month ago
Thanks @andrew2net for finding this. Indeed the current behavior is incorrect.
@HassanAkbar can you please help? Thanks.
@ronaldtse Sure, I'm looking into this
Is this now fixed with #86?
@ronaldtse Just found a minor issue will fix that with the specs in https://github.com/lutaml/lutaml-model/pull/85,
@ronaldtse I believe this is now fixed. can we close this now?
@HassanAkbar with GH version I get this error now:
class Item
attr_accessor :id
end
class BibItem < Lutaml::Model::Serializable
model Item
attribute :id, :string
xml do
root 'bibitem'
map_element "id", to: :id, with: { to: :id_to_xml, from: :id_from_xml }
end
def id_to_xml(model, doc)
doc[:did] = model.id
end
def id_from_xml(model, value)
model.id = value
end
end
> item = Item.new
> item.id = '123'
> BibItem.to_xml item
(irb):16:in `id_to_xml': wrong number of arguments (given 3, expected 2) (ArgumentError)
from /Users/andrej/.rvm/gems/ruby-3.3.3/gems/lutaml-model-0.3.10/lib/lutaml/model/xml_adapter/xml_document.rb:123:in `add_to_xml'
UPD It works. But method id_to_xml
should have 3 arguments id_to_xml(model, parent, doc)
. @HassanAkbar please update README here https://github.com/lutaml/lutaml-model?tab=readme-ov-file#attribute-serialization-with-custom-methods
Closing since done in #92.
With separate model custom methods are called on that model:
We shouldn't move serialization methods to separate models.