XStream
  1. XStream
  2. XSTR-97

Duplicate elements should cause an exception

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.0.2
    • Component/s: Converters
    • Labels:
      None

      Description

      — From Tom Ayerst —

      In our current xml marshalling/unmarshalling scheme we have code to spot duplicate elements in the xml (something historically managed to corrupt the xml). XStream deals with this silently:

      import com.thoughtworks.xstream.XStream;
      import junit.framework.TestCase;

      public class DuplicateElementTest extends TestCase {
      protected XStream converter = new XStream();

      public void testUniqueId()

      { String xml = "<TestFixture>" + "<uniqueId>1</uniqueId>" + "</TestFixture>"; TestFixture fixture = (TestFixture)converter.fromXML(xml); assertEquals(1, fixture.uniqueId); }

      public void testCorruptXml()

      { String xml = "<TestFixture>" + "<uniqueId>1</uniqueId>" + "<uniqueId>2</uniqueId>" + "</TestFixture>"; /** * I would expect some kind of exception here, xml does not conform to * class definition */ TestFixture fixture = (TestFixture)converter.fromXML(xml); assertEquals(1, fixture.uniqueId); }

      }

      class TestFixture {
      public int uniqueId;
      }
      testCorruptXml produces: junit.framework.AssertionFailedError: expected:<1> but was:<2>

      I would like to spot this with some kind of invalid mapping exception (to convince my team that XStream is better than our current solution (It is very, very much better!) ). Is this specified XStream behaviour? Does it already do it? I'm guessing that this behaviour helps deal with versioning issues etc. but the example above cannot be valid, can it?

      Cheers

      Tom

        People

        • Assignee:
          Unassigned
          Reporter:
          Joe Walnes
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: