lutaml / shale

Shale is a Ruby object mapper and serializer for JSON, YAML, TOML, CSV and XML. It allows you to parse JSON, YAML, TOML, CSV and XML data and convert it into Ruby data structures, as well as serialize data structures into JSON, YAML, TOML, CSV or XML.
https://shalerb.org/
MIT License
0 stars 1 forks source link

Interleaved element order does not work #2

Closed ronaldtse closed 2 months ago

ronaldtse commented 3 months ago

It does not support interleaved element orderings. It only supports fixed ordering, e.g. according to the declared element order.

xml do
  map_element 'a'
  map_element 'b'
end

Given:

<a>aaa</a><b>bbb</b><a>ccc</a><b>ddd</b>

Shale will return:

<a>aaa</a><a>ccc</a><b>bbb</b><b>ddd</b>

Because 'a' element is mapped before 'b'.

This ordering is very important in some schemas because it is positional.

ronaldtse commented 3 months ago

@HassanAkbar :

Actually, I updated this in the mapper. Let me share the commit with you.

https://github.com/lutaml/lutaml/blob/2a9f38b8ff6ff12298f1a2ba4092a43d9740d58f/lib/lutaml/xml/mapper.rb#L285

ronaldtse commented 3 months ago

@HassanAkbar this is causing failure here:

https://github.com/lutaml/ogc-gml/issues/1

                        <gml:GeodesicString>
                          <gml:posList>55.233333333333334 -36.166666666666664
                            55.23116372807667 -36.89437337916484</gml:posList>
                        </gml:GeodesicString>
       -                <gml:ArcByCenterPoint numArc="1">
       -                  <gml:posList>55.233333333333334 -36.166666666666664</gml:posList>
       -                  <gml:radius uom="NM">25.0</gml:radius>
       -                  <gml:startAngle uom="deg">270.0
       -                  </gml:startAngle>
       -                  <gml:endAngle uom="deg">497.0</gml:endAngle>
       -                </gml:ArcByCenterPoint>
                        <gml:GeodesicString>
                          <gml:posList>54.92816350530716 -35.674116070018954
                            55.233333333333334 -36.166666666666664</gml:posList>
                        </gml:GeodesicString>
       +                <gml:ArcByCenterPoint numArc="1">
       +                  <gml:posList>55.233333333333334 -36.166666666666664</gml:posList>
       +                  <gml:radius>#&lt;Ogc::Gml::Measure:0x00000001094ddaa0&gt;</gml:radius>
       +                  <gml:startAngle>#&lt;Ogc::Gml::Measure:0x00000001094dd280&gt;</gml:startAngle>
       +                  <gml:endAngle>#&lt;Ogc::Gml::Measure:0x00000001094dca88&gt;</gml:endAngle>
       +                </gml:ArcByCenterPoint>
                      </gml:segments>
HassanAkbar commented 3 months ago

@ronaldtse I've looked at the code at https://github.com/lutaml/ogc-gml/issues/1 and It is using the shale mapper and not the one that we have extended, I'll move the mapper to the shale fork and I think using that can fix the issue.