History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-276
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Assignee: Unassigned
Reporter: Daniel Frey
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XStream

Implicite Collections lead to duplicate id attribute in XML

Created: 20/Feb/06 03:34 AM   Updated: 07/Aug/06 09:13 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2

Issue Links:
Related
 

JDK version and platform:  1.4.2_08-b03


 Description  « Hide
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("windows-1252")));
                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

 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Daniel Frey - 20/Feb/06 03:46 AM
Actually it seems always to be the case. Even if the names are not identical.

Joerg Schaible - 15/Mar/06 03:13 PM
XStream does not write ids for implicit elements anymore. Any attempt to reference such an element results now in a ConverterException. Your case should be fixed now.