Discussion:
custom Map converter with XStreamImplicit anotation
Martin Minka
2012-05-23 18:55:36 UTC
Permalink
I would like to produce from a HashMap following XML:
<a id="map_key">map_value</a>

I tried:
@XStreamImplicit(keyFieldName = "a")
@XStreamConverter(MyMapConverter.class)
HashMap<String, String> map = new HashMap<String, String>();

But this combination never enters MyMapConverter.

Is there a way to achieve this ?

Thank you.
Jörg Schaible
2012-05-23 19:58:10 UTC
Permalink
Hi Martin,
Post by Martin Minka
<a id="map_key">map_value</a>
@XStreamImplicit(keyFieldName = "a")
@XStreamConverter(MyMapConverter.class)
HashMap<String, String> map = new HashMap<String, String>();
But this combination never enters MyMapConverter.
Is there a way to achieve this ?
No. Implicit collections/arrays/maps are a hack in the generic converters
(e.g. ReflectionConverter) to skip the "implicit" container and write their
elements like own elements. Therefore is no converter required/called for
the map. Your converter is only called without the implicit declaration.

- Jörg


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

http://xircles.codehaus.org/manage_email
Martin Minka
2012-05-23 20:59:52 UTC
Permalink
Jorg,
thank you for quick reply.

And is there a way for the converter to build output

<a id="map_key">map_value</a>

without implicit anotation ?
I don't need to use annotation, API would be also good.

Martin
Post by Jörg Schaible
Hi Martin,
Post by Martin Minka
<a id="map_key">map_value</a>
@XStreamImplicit(keyFieldName = "a")
@XStreamConverter(MyMapConverter.class)
HashMap<String, String> map = new HashMap<String, String>();
But this combination never enters MyMapConverter.
Is there a way to achieve this ?
No. Implicit collections/arrays/maps are a hack in the generic converters
(e.g. ReflectionConverter) to skip the "implicit" container and write their
elements like own elements. Therefore is no converter required/called for
the map. Your converter is only called without the implicit declaration.
- Jörg
---------------------------------------------------------------------
http://xircles.codehaus.org/manage_email
Jörg Schaible
2012-05-24 07:12:36 UTC
Permalink
Hi Martin,
Post by Martin Minka
Jorg,
thank you for quick reply.
And is there a way for the converter to build output
<a id="map_key">map_value</a>
without implicit anotation ?
I don't need to use annotation, API would be also good.
Implicit declaration by annotation or API make no difference, its the
implementation of the ReflectionProvider that skips your map in this case.
All you can do is to write a custom converter for the type that contains
this map.

- Jörg


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

http://xircles.codehaus.org/manage_email

Loading...