Jörg Schaible <joerg.schaible@...> writes:
>
> 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() {
> <at> 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
>
>
Hi
Actually i am using the custom converter.
so i am doing something like
public void marshal(Object source, HierarchicalStreamWriter writer,
MarshallingContext context) {
MCS mcs = (MCS) source;
//couple of the other customization here
if(mcs.getDesks()!=null)
context.convertAnother(mcs.getDesks(),new DeskCollectionConverter());
}
Now i want my DeskCollectionConverter to extend NamedCollectionConverter.
The
NamedCollectionConverter constructor parameters are
NamedCollectionConverter(Class type, Mapper mapper, String itemName, Class
itemType)
How to pass these parameters ?
I am learning and soon will be perfect with XStream.
Regards
Raj
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email