XStream
  1. XStream
  2. XSTR-198

Cannot serialize inner sets of HashMap

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: None
    • Labels:
      None
    • JDK version and platform:
      Sun 1.4.2_05 Win32

      Description

      The sets of a HashMap are not properly serialized. They do not have any elements in the XML representation and are additionally not properly unmarshalled, since the returned collection throws a NPE accessing the size method. Test cases below.

      ======= %< ========

      final public void testKeySetOfHashMapCanBeSerialized()

      { final Map map = new HashMap(); map.put("JUnit", null); final XStream xstream = new XStream(); final String xml = xstream.toXML(map.keySet()); final Collection collection = (Collection) xstream.fromXML(xml); assertNotNull(collection); assertEquals(1, collection.size()); assertEquals("JUnit", collection.iterator().next()); }

      final public void testValueSetOfHashMapCanBeSerialized()

      { final Map map = new HashMap(); map.put(Boolean.TRUE, "JUnit"); final XStream xstream = new XStream(); final String xml = xstream.toXML(map.values()); final Collection collection = (Collection) xstream.fromXML(xml); assertNotNull(collection); assertEquals(1, collection.size()); assertEquals("JUnit", collection.iterator().next()); }

      final public void testEntrySetOfHashMapCanBeSerialized()

      { final Map map = new HashMap(); map.put(Boolean.TRUE, "JUnit"); final XStream xstream = new XStream(); final String xml = xstream.toXML(map.entrySet()); final Collection collection = (Collection) xstream.fromXML(xml); assertNotNull(collection); assertEquals(1, collection.size()); final Map.Entry entry = (Map.Entry) collection.iterator().next(); assertEquals(Boolean.TRUE, entry.getKey()); assertEquals("JUnit", entry.getValue()); }

        People

        • Assignee:
          Unassigned
          Reporter:
          Jörg Schaible
        • Votes:
          0 Vote for this issue
          Watchers:
          0 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: