
|
If you were logged in you would be able to see more operations.
|
|
|
XStream
Created: 24/Apr/07 11:35 AM
Updated: 25/Feb/08 05:01 PM
|
|
| Component/s: |
None
|
| Affects Version/s: |
None
|
| Fix Version/s: |
1.3
|
|
|
File Attachments:
|
1.
src.zip (1 kb)
|
|
Issue Links:
|
dependent
|
|
|
|
This issue is depended upon by:
|
|
XSTR-413
@XStreamAsAttribute should support of enum types
|
|
|
|
|
|
|
| JDK version and platform: |
1.5+
|
|
Serialization of Java 5 Enum to/from xml attribute doesn't work:
xstream.useAttributeFor(MyEnum.class)
unless SingleValueConverter is registered:
xstream.registerConverter(EnumSingleValueConverter.create(MyEnum.class));
below (and in attachment) is the converter code:
public class EnumSingleValueConverter<T extends Enum<T>>
extends EnumConverter implements SingleValueConverter {
private Class<T> enumType;
public static <V extends Enum<V>> SingleValueConverter create(Class<V> enumClass) {
return new EnumSingleValueConverter<V>(enumClass);
}
private EnumSingleValueConverter(Class<T> newEnumType) {
this.enumType = newEnumType;
}
public boolean canConvert(Class type) {
return type == enumType;
}
public Object fromString(String str) {
return Enum.valueOf(enumType, str);
}
public String toString(Object obj) {
return obj.toString();
}
}
it should be possible to add support for that in XStream facade so user wouldn't have to register anything.
|
|
Description
|
Serialization of Java 5 Enum to/from xml attribute doesn't work:
xstream.useAttributeFor(MyEnum.class)
unless SingleValueConverter is registered:
xstream.registerConverter(EnumSingleValueConverter.create(MyEnum.class));
below (and in attachment) is the converter code:
public class EnumSingleValueConverter<T extends Enum<T>>
extends EnumConverter implements SingleValueConverter {
private Class<T> enumType;
public static <V extends Enum<V>> SingleValueConverter create(Class<V> enumClass) {
return new EnumSingleValueConverter<V>(enumClass);
}
private EnumSingleValueConverter(Class<T> newEnumType) {
this.enumType = newEnumType;
}
public boolean canConvert(Class type) {
return type == enumType;
}
public Object fromString(String str) {
return Enum.valueOf(enumType, str);
}
public String toString(Object obj) {
return obj.toString();
}
}
it should be possible to add support for that in XStream facade so user wouldn't have to register anything. |
Show » |
|