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

fix: overriding classes from lutaml type not working #271

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

HassanAkbar
Copy link
Member

This PR fixes the issue of the overrided methods in the inherited classes from Lutaml::Model::Type not working.

closes #224, closes #199

@HassanAkbar HassanAkbar marked this pull request as draft January 23, 2025 07:57
@HassanAkbar HassanAkbar marked this pull request as ready for review January 23, 2025 08:20
@HassanAkbar
Copy link
Member Author

@ronaldtse,
lutaml/reqif#1 should be solvable now as to_xml will be called for HighPrecisionDateTime after this fix.

@HassanAkbar HassanAkbar requested a review from ronaldtse January 23, 2025 08:59
@HassanAkbar
Copy link
Member Author

@ronaldtse, there are specs from genericode that are failing in this PR.
The reason is the mapping of the XML as follows:

      <Row>
         <Value ColumnRef="code">
            <SimpleValue>10</SimpleValue>
         </Value>
         <Value ColumnRef="name">
            <SimpleValue>group</SimpleValue>
         </Value>
         <Value ColumnRef="description">
            <SimpleValue>A unit of count defining the number of groups (group: set of items classified together).</SimpleValue>
         </Value>
         <Value ColumnRef="levelcategory">
            <SimpleValue>3.9</SimpleValue>
         </Value>
      </Row>

In the above example XML, the mapping of ColumnRef in a Value should be to a String, Instead, it is to a class ColumnRef which has the following definition:

class ColumnRef < Lutaml::Model::Serializable
    attribute :id, :string
    attribute :external_ref, :string
    attribute :use, :string
    attribute :annotation, Annotation
    attribute :canonical_version_uri, :string
    attribute :location_uri, :string, collection: true
    attribute :data, DataRestrictions

    xml do
      root "ColumnRef"
      namespace "http://docs.oasis-open.org/codelist/ns/genericode/1.0/", "gc"

      map_attribute "Id", to: :id
      map_attribute "ExternalRef", to: :external_ref
      map_attribute "Use", to: :use
      map_element "Annotation", to: :annotation, prefix: nil, namespace: nil
      map_element "CanonicalVersionUri", to: :canonical_version_uri, prefix: nil, namespace: nil
      map_element "LocationUri", to: :location_uri, prefix: nil, namespace: nil
      map_element "Data", to: :data, prefix: nil, namespace: nil
    end
  end

So as per the change in our PR:

We are now calling from_#{format} to support deserialization using the override methods. But when from_#{format} is called on ColumnRef, It breaks since the value is a string i.e “description” but the type is ColumnRef that should be deserialized using its own attributes but the code breaks.

Please let me know what should we do in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom DateTime type doesn't call to_xml Overriding classes inherited from Lutaml::Type doesn't work?
1 participant