castor
  1. castor
  2. CASTOR-1582

Castor has inconsistant marshalling of HashMaps when used with xml binding for MapItem

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.0.2
    • Fix Version/s: 1.0.4
    • Component/s: XML
    • Labels:
      None
    • Environment:
      Sun JRE 5.0
    • Testcase included:
      yes
    • Number of attachments :
      6

      Description

      The issue appears when getting castor to marshall / unmarshall a HashMap with
      xml binding provided in the castor mapping file and schema validation.

      The castor mapping has been specified to provide the key/value pair
      as named attributes, and a schema defined to expect this format.

      e.g. as shown in the hand-coded marshalled data:

      <CountryCode isoNumeric='266' name='Gabon'/>

      When castor itself marshals the data, it appears to disregard the supplementary
      mapping specified in the castor map and instead writes out the map with key and
      value element pairs:

      <CountryCode>
      <key>270</key>
      <value>Gambia</value>
      </CountryCode>

      As the provided schema (and castor map) has been told to expect attributes
      called isoNumeric and name, this fails when the castor marshalled data
      is unmarshalled because the xml fails against the schema.

      The castor mapping for these attributes is specified as:

      <field name='Translator' type='java.util.HashMap' collection='map'>
      <bind-xml name='CountryCode'>
      <class name='org.exolab.castor.mapping.MapItem'>
      <field name='key' type='java.lang.String'>
      <bind-xml name='isoNumeric' node='attribute'/>
      </field>
      <field name='value' type='java.lang.String'>
      <bind-xml name='name' node='attribute'/>
      </field>
      </class>
      </bind-xml>
      </field>

      1. MappingDtoTest.java
        7 kB
        Graham Coles
      2. Readme.txt
        2 kB
        Graham Coles
      3. MappingDto.java
        0.5 kB
        Graham Coles
      4. MappingCastorMap.xml
        0.9 kB
        Graham Coles
      5. country.xsd
        0.7 kB
        Graham Coles
      6. patch.c1582.20060927.txt
        10 kB
        Werner Guttmann

        Activity

        Hide
        Werner Guttmann added a comment -

        Graham, can you please attach all relevant files, e.g. mapping file, MappingDto.Java, etc.. ?

        Show
        Werner Guttmann added a comment - Graham, can you please attach all relevant files, e.g. mapping file, MappingDto.Java, etc.. ?
        Hide
        Graham Coles added a comment -

        Not actually required by the test case as it is hard coded internally, however reproduced for convenience.

        Show
        Graham Coles added a comment - Not actually required by the test case as it is hard coded internally, however reproduced for convenience.
        Hide
        Graham Coles added a comment -

        Schema for validation - created + deleted by unit test.

        Show
        Graham Coles added a comment - Schema for validation - created + deleted by unit test.
        Hide
        Werner Guttmann added a comment -

        Graham, if you changed the field mapping for 'Translator' to

        <field name="Translator" collection="map">
        <bind-xml name="CountryCode">
        </field>

        by dropping the type="java.util.HashMap", your tests completes just fine.

        Show
        Werner Guttmann added a comment - Graham, if you changed the field mapping for 'Translator' to <field name="Translator" collection="map"> <bind-xml name="CountryCode"> </field> by dropping the type="java.util.HashMap", your tests completes just fine.
        Hide
        Werner Guttmann added a comment -

        Having said that, I think we shoudl try to find out why using the type attribute erenders the existing code non-working.

        Show
        Werner Guttmann added a comment - Having said that, I think we shoudl try to find out why using the type attribute erenders the existing code non-working.
        Hide
        Werner Guttmann added a comment -

        Resolving thisa as 'Won't fix'. Graham, please feel free to reopen this issue if you thin something else should be addressed.

        [For myself and Steven: let's address the incorrect behavior when teh type attribute is specified as above in a separate issue].

        Show
        Werner Guttmann added a comment - Resolving thisa as 'Won't fix'. Graham, please feel free to reopen this issue if you thin something else should be addressed. [For myself and Steven: let's address the incorrect behavior when teh type attribute is specified as above in a separate issue] .
        Hide
        Werner Guttmann added a comment -

        Mabe we should simply throw an exception if both type attribute and MapItem are used ?

        Show
        Werner Guttmann added a comment - Mabe we should simply throw an exception if both type attribute and MapItem are used ?

          People

          • Assignee:
            Werner Guttmann
            Reporter:
            Graham Coles
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: