Details
-
Type: Bug
-
Status: 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()); }
This test works fine on 1.2, anyone using 1.1 can switch now.