Skip to content
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

Custom methods and separate model 2 #200

Open
andrew2net opened this issue Dec 7, 2024 · 0 comments
Open

Custom methods and separate model 2 #200

andrew2net opened this issue Dec 7, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@andrew2net
Copy link

Custom methods for map_content are called on a separate model

class TestModel
  attr_accessor :value
end

class Test < Lutaml::Model::Serializable
  model TestModel
  attribute :value, :string
  xml do
    root 'test'
    map_content to: :value, with: { to: :value_to_xml, from: :value_from_xml }
  end

  def value_to_xml(model, parent, doc)
    el = doc.create_element('cont')
    doc.add_text(el, model.value)
    doc.add_element(parent, el)
  end

  def value_from_xml(model, value)
    model.value = value
  end
end

> test = TestModel.new
> test.value='Val'
> Test.to_xml(test)
.../gems/ruby-3.3.3/gems/lutaml-model-0.3.30/lib/lutaml/model/xml_adapter/xml_document.rb:244:in `process_content_mapping': undefined method `value_to_xml' for an instance of TestModel (NoMethodError)

We had a similar problem with the map_element method #83

@andrew2net andrew2net added the bug Something isn't working label Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants