The basic problem is that I can marshal and unmarshal a Map with key=Integer and value=AddressObject and it works fine

When I try to use a reference to AddressObject, it “almost” works.

 

Any help will  be appreciated  Hope I can use references, our maps generally have duplicate objects in the keyset and don’t want to repeat the data, and more importantly want to insure they are unmarshaled properly.

 

 

Details below:

 

 

Got the map working sort of just fine in a vanilla way.  I make one change to the mapping to use a reference and all of a sudden Castor appears to want to populate my map with it’s  “org.exolab.castor.mapping.MapItem” as the Map value, rather than the real object.

 

Excerpt from mapping file:

 

            <!-- Hashmap of with key as Role and Value as Address -->

                <field name="addressMap"

                       type="org.exolab.castor.mapping.MapItem" collection="map"

                       get-method="getAddressMap" set-method="setAddressMap" >

                        <bind-xml>

                            <class name= "org.exolab.castor.mapping.MapItem">

                                <field name="key" type="integer">

                                    <bind-xml name="role" node = "element"/>

                                 </field>

                                 <field name="value" type="com.trivin.bo.party.Address">

                                     <bind-xml name="Address" node="element" />

                                </field>

                             </class>

                        </bind-xml>

                </field>

            <!-- End Map of Address References -->

 

Marshalling to and from works fine.  My test marshals, unmarshals, and marshals.  To marshaled xml files look good and like this:

 

    <addressMap>

        <role>2</role>

        <Address zipCode="06340" state="CT" country="USA"

            street1="1234 Main St" city="Groton" county="Trumbull" key="7443611"/>

    </addressMap>

    <addressMap>

        <role>3</role>

        <Address zipCode="06340" state="CT" country="USA"

            street1="1234 Main St" city="Groton" county="Trumbull" key="7443611"/>

    </addressMap>

 

OK, note that the 2 addresses are actually the same object.  So, now I want to use reference on key.

 

No I Change:

                                     <bind-xml name="Address" node="element" />

To

                                     <bind-xml name="Address" node="element" reference=”true” />

 

 

===========  Now the  problem ===========

It marshals to something like below.  So far, so good.  2 references to the same address object

 

 

   <addressMap>

        <role>2</role>

        <Address>18141583</Address>

    </addressMap>

    <addressMap>

        <role>3</role>

        <Address>18141583</Address>

    </addressMap>

    <Addresses>

        <Address zipCode="06340" state="CT" country="USA"

            street1="1234 Main St" city="Groton" county="Trumbull" key="18141583"/>

    </Addresses>

 

 

When the above XML get’s turned around and marshaled back into another object, the Map contains 'org.exolab.castor.mapping.MapItem” as values, instead of “Address” objects, which I confirmed in the debugger.

 

And also sort of confirmed by the fact when I turn around and try to unMarshal said object, Castor doesn’t like it because it is looking for an “Address” object as a value, and it is no longer there.

 

 

 

Unable to resolve ID for instance of class 'org.exolab.castor.mapping.MapItem' due to the following error: No identity descriptor available

 

SEVERE: Error marshalling Object

Unable to resolve ID for instance of class 'org.exolab.castor.mapping.MapItem' due to the following error: No identity descriptor available

            at org.exolab.castor.xml.Marshaller.getObjectID(Marshaller.java:1652)

            at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1326)

            at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1507)

            at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1490)

            at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:785)

            at com.trivin.msg.xml.ERTMarshall.marshal(ERTMarshall.java:159)

            at com.trivin.msg.xml.ERTMarshall.marshal(ERTMarshall.java:145)

            at test.MessageApplet.testMarshal(MessageApplet.java:132)

            at test.MessageApplet.castorTest(MessageApplet.java:181)

            at test.MessageApplet.castorTest(MessageApplet.java:113)

            at test.MessageApplet.butBusiness_actionPerformed(MessageApplet.java:1034)

            at test.MessageApplet_butBusiness_actionAdapter.actionPerformed(MessageApplet.java:1339)

 

Reply via email to