Hi Jirka,
Jirka wrote:
> Hi,
>
> thanks for your answer. I tried that (I should have said it), this is my
> co= de
>
> @XStreamAlias("printer")
> @XStreamConverter(ColumnPrinterConverter.class)
> private ColumnPrinter<?> printer;
>
> :
>
> public static class ColumnPrinterConverter implements Converter {
> public void marshal(Object source, HierarchicalStreamWriter
> writer, MarshallingContext context) {
> ColumnPrinter printer =3D (ColumnPrinter) source;
> writer.setValue(printer.getId());
> }
>
> public Object unmarshal(HierarchicalStreamReader reader,
> UnmarshallingContext context) {
> String id =3D (String) reader.getValue();
> return ColumnPrinters.getDef().getPrinter(id);
> }
>
> public boolean canConvert(Class type) {
> return ColumnPrinter.class.isAssignableFrom(type);
> }
> }
>
> However, this still includes the class attribute. So it probably
> creates instance of that class on unmarshalling (or not?) only to
> throw it away, which could cause problems if the anonymous classes are
> reordered.
>
> <printer class=3D"org.purl.jh.feat.navigator.ColumnPrinters$6">
> id19
> </printer>
In this case you should drop the alias annotation above and use
xstream.aliasType(...) instead defining an alias for all types assignable to
a specific interface or superclass. It's then in the responsibility for the
converter to create the real appropriate type, but that's what your
converter does.
- Jörg
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email