JiBX
  1. JiBX
  2. JIBX-89

Trying to use a mapping as both a structure and a collection does not work.

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core
    • Labels:
      None
    • Environment:
      Windows 2K, Oracle JDeveloper
    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      This affect RC2, I've attached the binding file, the source data files and the example xml file.

      I have a mapping (short version):

      <mapping class="com.softstart.stellar.data.HexID" post-set="convertHextoID" abstract="true">
      <value style="attribute" name="type" field="hexType" />
      <value style="attribute" name="group" field="hexGroup" />
      <value style="text" field="hex" />
      </mapping>

      I would like to use this mapping in two ways, as a structure in one mapping:

      <mapping name="system" class="com.softstart.stellar.data.StarSystem" post-set="update">
      <value style="attribute" name="id" field="key" />
      <value style="attribute" name="provider" field="providerName" usage="optional" />
      <value name="name" field="name" />
      <structure field="location" name="location"/>
      </mapping>

      and as a collection of locations in another mapping:

      <mapping name="link" class="com.softstart.stellar.data.Links">
      <structure map-as="com.softstart.stellar.data.Record" />
      <collection field="hexes" item-type="com.softstart.stellar.data.HexID"/>
      <value style="attribute" name="linkType" field="linkTypeName" usage="optional"/>
      </mapping>

      In order for the second mapping to work (the links collection) I need to give the HexID mapping a name attribute. But if I do so the system mapping fails on reading, because it's now looking for a nested <location><location> tag.

        Activity

        Hide
        Dennis Sosnoski added a comment -

        You just need to add a <structure> child to the collection, so that you can give a name to the component HexIDs:

        <collection field="hexes">
        <structure type="com.softstart.stellar.data.HexID" name="location"/>
        </collection>

        I did find a couple of other issues in the binding. One was that you were (unintentionally, I'm sure) using the default char handling (which treats it as an unsigned short value). To make your AccessXML test code work I had to first add:

        <format type="char"
        serializer="org.jibx.runtime.Utility.serializeCharString"
        deserializer="org.jibx.runtime.Utility.deserializeCharString"/>

        as a child of the <binding> element, in order to force handling of char values as single character strings rather than unsigned shorts. I also changed your StarSystem.deserializeMaybeEmptyZone() method to just return a char value:

        public static char deserializeMaybeEmptyZone(String text) throws JiBXException

        {

        if (text.length() == 0)

        { return ' '; }

        else

        { return text.charAt(0); }

        }

        After these changes the test seemed to run okay.

        Show
        Dennis Sosnoski added a comment - You just need to add a <structure> child to the collection, so that you can give a name to the component HexIDs: <collection field="hexes"> <structure type="com.softstart.stellar.data.HexID" name="location"/> </collection> I did find a couple of other issues in the binding. One was that you were (unintentionally, I'm sure) using the default char handling (which treats it as an unsigned short value). To make your AccessXML test code work I had to first add: <format type="char" serializer="org.jibx.runtime.Utility.serializeCharString" deserializer="org.jibx.runtime.Utility.deserializeCharString"/> as a child of the <binding> element, in order to force handling of char values as single character strings rather than unsigned shorts. I also changed your StarSystem.deserializeMaybeEmptyZone() method to just return a char value: public static char deserializeMaybeEmptyZone(String text) throws JiBXException { if (text.length() == 0) { return ' '; } else { return text.charAt(0); } } After these changes the test seemed to run okay.

          People

          • Assignee:
            Dennis Sosnoski
            Reporter:
            Thomas Jones-Low
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: