Gmane
From: Jörg Schaible <Joerg.Schaible@...>
Subject: RE: Re: polymorphic enums
Newsgroups: gmane.comp.java.xstream.user
Date: 2008-02-11 17:36:03 GMT (21 weeks, 1 day, 18 hours and 27 minutes ago)
Hi Hari,

Hari Krishna Dara wrote:

[snip]

> But I do
> have more information now and I can confirm that it is a bug when
> handling enums. During one of the writeFields() implementations (to be
> precise, at AbstractRefectionConverter:102), the lookup for default
> implementation of my interface does find what I configure, however,
> the actualType is always different from that of defaultType for enums.
> E.g., if the following is the scenario:
> 
> interface EnumI {
> }
> 
> enum EnumT implements EnumI {
>     ENUM1,
>     ENUM2
> }
> 
> while writing the below field:
> 
> EnumI et = EnumT.ENUM1;
> 
> the newObj here would be EnumT.ENUM1 and its actualType would always
> be EnumT$1 (while for EnumT.ENUM2 it would be EnumT$2 etc.) so the
> below condition fails and ends up writing the class attribute:
> 
>                 if (!actualType.equals(defaultType)) {
> 
> writer.addAttribute(mapper.aliasForAttribute("class"),
> mapper.serializedClass(actualType));
>                 }
> 
> It is weird that it doesn't actually write the type with $1 suffix
> though (I didn't debug all the way). 

This is done by the EnumMapper.

>Is there a workaround for this
> problem (if not already fixed)?

I fear you've hit a bug and please open a JIRA issue for your case. As workaround you should register an own
ReflectionConverter. Simply copy the original code and put it into your private package. You may add an
additional test and write the attribute only if the mapper returns different names with serializedClass
for the defaultType and the actualType.

- Jörg

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

    http://xircles.codehaus.org/manage_email