addthis / stream-lib

Stream summarizer and cardinality estimator.
Apache License 2.0
2.26k stars 556 forks source link

Counter/StreamSummary class can't deserialize non-primitive type #143

Closed orchesio closed 7 years ago

orchesio commented 7 years ago

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());
        }
orchesio commented 7 years ago

Close as it turned out to be field serialization problem of CustKey class.