Jörg Schaible wrote:

> Hi Raj,
> 
> Raj wrote:
> 
>> Hi
>> 
>> Thanks for quick repsonses.
>> 
>> I have map below.
>> 
>> Map<String,Set<String>> desksDetails = new HashMap<String,
>> Set<String>>();
>> 
>> Map key is "ABC"
>> and value is Set holding usernames.
>> 
>> I want to covert this into xml like
>> <desk name="ABC">
>>         <user name="rpaynter"/>
>>         <user name="yatesn"/>
>>         <user name="gnishok"/>
>>         <user name="bingminc"/>
>>         <user name="nixmar"/>
>>         <user name="tanyun"/>
>>         <user name="choo"/>
>> </desk>
>> 
>> I looked into NamedMapConverter but the map here is key,value as String.
>> In my case value is collection.
>> 
>> Any pointer will be higly appreciated.
> 
> 
> Did you try:
> 
>  new NamedMapConverter(xstream.getMapper(), "desk", "name", String.class,
>    null, HashSet.class, true, false, xstream.getConverterLookup());
> 
> That should be written as:
> 
>  <map>
>    <desk name="ABC">
>       <string>rpaynter</string>
>       <!-- rest omitted -->
>    </entry>
>  </map>
> 
> You will have to register an additional NamedCollectionConverter for
> HashSet in general though to influence the inner set. However, that would
> affect any HashSet in your object graph.
> 
> The only alternative is otherwise a gain a custom converter, probably
> derived from the MapConverter.

Actually there's a third option by injecting a modified ConverterLookup:

  new NamedMapConverter(xstream.getMapper(), "desk", "name", String.class,
    null, HashSet.class, true, false, new ConverterLookup() {
    @Override
    Converter lookupConverterForClass(Class type) {
      if (type == HashSet.class) {
        return new NamedCollectionConverter( ... );
      } else
        return xstream.getConverterLookup().lookupConverterForClass(type);
    }
  });

You get the idea ...

Cheers,
Jörg


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

    http://xircles.codehaus.org/manage_email


Reply via email to