XStream
  1. XStream
  2. XSTR-448

Cannot use "class" as an attribute alias

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major 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)

      { return type.equals(Attribute.class); }

      @Override
      public String toString(Object obj)

      { return obj == null ? null : ((Attribute) obj).value; }

      @Override
      public Object fromString(String name)

      { return new Attribute(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

          People

          • Assignee:
            Jörg Schaible
            Reporter:
            Don Ngo
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: