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

Inheritance: support retaining existing attributes and selective overriding #69

Open
ronaldtse opened this issue Sep 8, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@ronaldtse
Copy link
Contributor

ronaldtse commented Sep 8, 2024

When inheriting a Serializable class, sometimes we want to retain the existing mappings, and add additional attributes.

Maybe we use a xml(keep: true) do syntax (by default true), e.g. {format}(keep: false) do.

Case 1: add attribute and element

class Klin < Lutaml::Model::Serializable
  attribute :manufacturer, :string
  xml do
    map_element "manufacturer", to: :manufacturer
  end
end

class GlassKlin < Klin
  attribute :max_temp, :integer
  xml(keep: true) do
    map_element "max-temp", to: :max_temp
  end
end

Case 2: modify attribute and element

class Klin < Lutaml::Model::Serializable
  attribute :manufacturer, :string
  xml(keep: false) do
    map_element "manufacturer", to: :manufacturer
  end
end

class Manufacturer < Lutaml::Model::Serializable
end

class GlassKlin < Klin
  attribute :manufacturer, Manufacturer
end

Case 3: modify mapping

class Klin < Lutaml::Model::Serializable
  attribute :manufacturer, :string
  xml do
    map_element "manufacturer", to: :manufacturer
  end
end

class GlassKlin < Klin
  xml do
    map_element "make", to: :manufacturer
    remove_map_element "manufacturer" # is this the best way to delete a mapping?
  end
end
@ronaldtse ronaldtse changed the title Support inheriting and modifying selective elements in xml_mapping Inheritance: support retaining existing attributes and selective overriding Sep 11, 2024
@ronaldtse ronaldtse added the enhancement New feature or request label Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant