Change a HashMap to TreeMap -> don't specify a Comparator?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Change a HashMap to TreeMap -> don't specify a Comparator?

Spence, Jamie

Hi There,

 

I was previously using xStream to deserialzise a HashMap<String,Object>, but I would like to change this to TreeMap<String,Object> to introduce ordering on the String key. Is there a way of overriding the TreeMap converter to keep the current structure of my XML files (I want the same serialised structure as a HashMap)?

 

Regards,

Jamie

 


This e-mail may contain privileged or confidential information. If you are not the intended recipient: (1) you may not disclose, use, distribute, copy or rely upon this message or attachment(s); and (2) please notify the sender by reply e-mail, and then delete this message and its attachment(s). Underwriters Laboratories Inc. and its affiliates disclaim all liability for any errors, omissions, corruption or virus in this message or any attachments.

Reply | Threaded
Open this post in threaded view
|

Re: Change a HashMap to TreeMap -> don't specify a Comparator?

Jörg Schaible-2
Hi Jamie,

Spence, Jamie wrote:

> Hi There,
>
> I was previously using xStream to deserialzise a HashMap<String,Object>,
> but I would like to change this to TreeMap<String,Object> to introduce
> ordering on the String key. Is there a way of overriding the TreeMap
> converter to keep the current structure of my XML files (I want the same
> serialised structure as a HashMap)?

XStream uses by default the <map> element, but just because it calls
internally at initialization time:

 this.addDefaultImplementation(HashMap.class, Map.class);

So you can call this method a second time with TreeMap as default for a Map
implementation.

Cheers,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email