The serialization of Counter class seems like doesn't work with generic types. In following test case the deserialized Item object from c.getItem() is always null. My CustKey class does implement Serializable interfaces.
CustKey key1 = new CustKey();
key1.setField("f0k1", 0);
key1.setField("f1k1", 1);
CustKey key2 = new CustKey();
key2.setField("f0k2", 0);
key2.setField("f1k2", 1);
sum.offer(key1, 1);
sum.offer(key2, 2);
sum.offer(key1, 1);
sum.offer(key2, 2);
List<Counter<CustKey>> topK = sum.topK(1);
for (Counter<CustKey> c : topK) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutput oo = new ObjectOutputStream(baos);
oo.writeObject(c);
oo.close();
ObjectInput oi = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
Counter<CustKey> clone = (Counter<CustKey>) oi.readObject();
assertEquals(c.getCount(), clone.getCount());
assertEquals(c.getError(), clone.getError());
System.out.println("item is " + (CustKey)c.getItem());
//assertEquals(c.getItem(), clone.getItem());
}
The serialization of Counter class seems like doesn't work with generic types. In following test case the deserialized Item object from c.getItem() is always null. My CustKey class does implement Serializable interfaces.