Hi Jeremy

Some upgrades were included in the 0.9.5.3 RC.

When using default introspection, you should notice these changes right
away, as both the key and value are now output by default.

When using a mapping file you need to specify this by using Castor's
built-in wrapper:


Try the following:

<field name="..." type="org.exolab.castor.mapping.MapItem"
collection="map"/>

You don't need to put MapItem's in your map. Castor automatically
creates the MapItem  internally for it's own use during
marshalling/unmarshalling.

You could also try not specifying the type. I think it defaults to
MapItem.


In addition, you can control the names of the element tags by specifying
a mapping for the MapItem class:

      <class name="org.exolab.castor.mapping.MapItem">
         <field name="key" type="java.lang.Object">
              <bind-xml name="id" node="element"/>
         </field>
         <field name="value" type="java.lang.Object"/>
      </class>

The above will change the default name from "<key>" to "<id>". for the
key field.

If you have more than one map and you want to have different mappings
for each one, you can now also use an inline class mapping directly
inside the bind-xml element as such:


<field name="..." type="...MapItem" collection="map">

   <bind-xml>
      <class name="org.exolab.castor.mapping.MapItem">
         <field name="key" type="java.lang.Object">
              <bind-xml name="id" node="element"/>
         </field>
         <field name="value" type="java.lang.Object"/>
      </class>
  </bind-xml>

</field>


Hope that helps,

--Keith



Jeremy Haile wrote:
> 
> OK, so this has been mentioned on the list and there are several bugzilla
> reports about better support for java.util.Map.  Was this support added
> in 0.9.5.3?  Is there any approximate schedule for when this support will
> be added?
> 
> Currently the best way to "map" a java.util.Map object is either using a
> wrapper object in the XML and a custom FieldHandler to convert to and
> from the Map object, or have the key and value be the same (which doesn't
> work in most situations) - is that correct?
> 
> I simply want to do a string to string mapping using a java.util.Map.  If
> someone could provide an example of the current best practice for maps, I
> would appreciate it.
> --
>   Jeremy Haile
>   [EMAIL PROTECTED]
> 
> -----------------------------------------------------------
> If you wish to unsubscribe from this mailing, send mail to
> [EMAIL PROTECTED] with a subject of:
>         unsubscribe castor-dev

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to