XStream
  1. XStream
  2. XSTR-299

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

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: None
    • Labels:
      None

      Description

      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)

        People

        • Assignee:
          Unassigned
          Reporter:
          David Blevins
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: