Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.2.2
-
Fix Version/s: 1.3.1
-
Component/s: None
-
Labels:None
-
JDK version and platform:Sun 1.6.0_03-b05 for Windows
Description
Why can't I use "class" as an attribute name? Whenever I tried, an exception is thrown. Is this a bug or am I doing something wrong here? Please see the code below.
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.SingleValueConverter;
public class Software {
private static class AttributeConverter implements SingleValueConverter {
@SuppressWarnings("unchecked")
@Override
public boolean canConvert(Class type)
@Override
public String toString(Object obj)
@Override
public Object fromString(String name)
}
private static class Attribute {
public String value;
public Attribute(String value)
{ this.value = value; }}
public Attribute clazz;
public static void main(String[] args)
{ String xml = "<software id=\"test\"/>"; // Using "id" as an attribute is fine, // String xml = "<software class=\"test\"/>"; // but using "class" won't work!! XStream xstream = new XStream(); xstream.alias("software", Software.class); xstream.aliasAttribute("id", "clazz"); // Using "id" as an alias is fine, //xstream.aliasAttribute("class", "clazz"); // but using "class" won't work!! xstream.useAttributeFor("clazz", Attribute.class); xstream.registerConverter(new AttributeConverter()); Software sw = (Software) xstream.fromXML(xml); System.out.println(xstream.toXML(sw)); }}
Issue Links
- is duplicated by
-
XSTR-520
XML with attribute call 'reference'
-