mirror of
https://github.com/corda/corda.git
synced 2025-06-17 14:48:16 +00:00
Make TreeMap (de)serialization compatible with Java
This is done by implementing the readObject()/writeObject() method pair as demanded by the serialization specification. The specifics were reverse-engineered from serializing trivial TreeMap instances with OpenJDK. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
@ -10,6 +10,10 @@
|
|||||||
|
|
||||||
package java.util;
|
package java.util;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
|
||||||
public class TreeMap<K,V> implements Map<K,V> {
|
public class TreeMap<K,V> implements Map<K,V> {
|
||||||
private final Comparator<K> comparator;
|
private final Comparator<K> comparator;
|
||||||
private transient TreeSet<MyEntry<K,V>> set;
|
private transient TreeSet<MyEntry<K,V>> set;
|
||||||
@ -232,4 +236,26 @@ public class TreeMap<K,V> implements Map<K,V> {
|
|||||||
return new Collections.ValueIterator(set.iterator());
|
return new Collections.ValueIterator(set.iterator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final static long serialVersionUID = 0x0cc1f63e2d256ae6l;
|
||||||
|
|
||||||
|
private void writeObject(ObjectOutputStream out) throws IOException {
|
||||||
|
out.defaultWriteObject();
|
||||||
|
out.writeInt(size());
|
||||||
|
for (Entry<K, V> entry : entrySet()) {
|
||||||
|
out.writeObject(entry.getKey());
|
||||||
|
out.writeObject(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readObject(ObjectInputStream in) throws IOException {
|
||||||
|
in.defaultReadObject();
|
||||||
|
initializeSet();
|
||||||
|
int size = in.readInt();
|
||||||
|
for (int i = 0; i < size; i++) try {
|
||||||
|
put((K) in.readObject(), (V) in.readObject());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user