Issue Details (XML | Word | Printable)

Key: XSTR-299
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Assignee: Unassigned
Reporter: David Blevins
Votes: 0
Watchers: 0
Operations

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

Implicit collections break if xml items are named after the implicit collection

Created: 16/Apr/06 12:29 AM   Updated: 07/Aug/06 09:08 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 1.2

File Attachments: 1. Text File AbstractReflectionConverter.java.patch (5 kB)
2. Text File ImplicitCollectionTest.java.patch (1 kB)



 Description  « Hide
Attached test case demonstrates. Here it is for easy browsing:

public static class Aquarium extends StandardObject {
private String name;
private LinkedList fish = new LinkedList();

public Aquarium(String name) { this.name = name; }

public void addFish(String fish) { this.fish.add(fish); }
}

public void testMatchingXmlElementAndJavaFieldName() { Aquarium aquarium = new Aquarium("hatchery"); aquarium.addFish("salmon"); aquarium.addFish("halibut"); aquarium.addFish("snapper"); String expected = "" + "<aquarium>\n" + " <name>hatchery</name>\n" + " <fish>salmon</fish>\n" + " <fish>halibut</fish>\n" + " <fish>snapper</fish>\n" + "</aquarium>"; xstream.alias("aquarium", Aquarium.class); xstream.addImplicitCollection(Aquarium.class, "fish", "fish", String.class); assertBothWays(aquarium, expected); }

Results in this error:

com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$DuplicateFieldException: fish
---- Debugging information ----
required-type : com.thoughtworks.acceptance.ImplicitCollectionTest$Aquarium
class : com.thoughtworks.acceptance.ImplicitCollectionTest$Aquarium
line number : 4
path : /aquarium/fish[2]
-------------------------------
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$SeenFields.add(AbstractReflectionConverter.java:234)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:167)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:117)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:789)
at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:777)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:731)
at com.thoughtworks.xstream.XStream.fromXML(XStream.java:724)



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
David Blevins added a comment - 16/Apr/06 12:33 AM
Just a note, this only affects unmarshalling. Marshalling works fine.

David Blevins added a comment - 16/Apr/06 05:45 AM
This patch to AbstractReflectionConverter that fixes the issue identified by the previously attached test case.

Joerg Schaible added a comment - 18/Apr/06 01:43 PM
Hi David,

thanks for detecting this. I've applied a different patch that also fixes the issue.

Regards,
Jörg


David Blevins added a comment - 18/Apr/06 02:01 PM
Oh that's definitely a smaller fix. Thanks for checking in my test case!