[PATCH] Simplification of TreeMap
Сергей Цыпанов
sergei.tsypanov at yandex.ru
Wed Sep 5 18:30:18 UTC 2018
Hi Michael,
thanks for pointing out this serialization concern, I didn't think about it at all.
I've wrote a simple test for serialization of patched TreeMap and it works without errors for both no-args constructor and constructor with comparator:
public class TreeMapSerialization {
public static void main(String[] args) throws Exception {
TreeMap<Integer, String> serialized = new TreeMap<>(Comparator.reverseOrder());
serialized.put(1, "1");
serialized.put(2, "2");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(serialized);
oos.flush();
baos.flush();
oos.close();
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois = new ObjectInputStream(bais);
TreeMap<Integer, String> deserialized = (TreeMap<Integer, String>) ois.readObject();
deserialized.put(3, "3");
System.out.println(deserialized);
}
}
I hope I don't miss anything, so there shouldn't be any serialization issues.
Regards,
Sergey Tsypanov
More information about the core-libs-dev
mailing list