Details
-
Type: New Feature
-
Status: Closed
-
Priority: Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.1.3
-
Component/s: Converters
-
Labels:None
Description
From Eric Snell
Great product. I don't have time to become a developer right now, but I wanted to make this contribution. I'm using 1.5 and needed an Enum converter. Hope this method helps:
private void installEnumConverter(XStream stream) {
final Converter converter = stream.getConverterLookup().lookupConverterForType(Enum.class);
if (converter.getClass() == ReflectionConverter.class) {
stream.registerConverter(new Converter() {
public boolean canConvert(Class type)
public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context)
{ converter.marshal(source, writer, context); }public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context)
{ Enum rc = (Enum)converter.unmarshal(reader, context); return Enum.valueOf(rc.getDeclaringClass(), rc.name()); } });
}
}
Support for EnumMap and EnumSet also useful.