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)