XStream
  1. XStream
  2. XSTR-276

Implicite Collections lead to duplicate id attribute in XML

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: None
    • Labels:
      None
    • JDK version and platform:
       1.4.2_08-b03

      Description

      Using a class with an implicite collection that has the same name as the class causes a doublicate id to be generated. Here is the test code:

      public class Main {
      public static void main(String[] args) {
      final XStream x = new XStream(new DomDriver(new ClassPathEntityResolver("utf-8")));
      x.setMode(XStream.ID_REFERENCES);
      x.alias("strings", Strings.class);
      x.addImplicitCollection(Strings.class, "strings");
      final Strings m = new Strings(new String[]

      {"Hallo", "Daniel"}

      );
      System.out.println(x.toXML(m));
      }
      }

      class Strings {
      private ArrayList strings = new ArrayList();
      public Strings(String[] strings)

      { this.strings.addAll(Arrays.asList(strings)); }

      }

      Leads to:

      <strings id="1" id="2">
      <string>Hallo</string>
      <string>Daniel</string>
      </strings>

      Cheers
      Daniel

        Issue Links

          People

          • Assignee:
            Unassigned
            Reporter:
            Daniel Frey
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: