Kryo serialization issues with BigInteger, BigDecimal, Timestamp

245 views
Skip to first unread message

Vootla

unread,
Mar 24, 2010, 6:20:52 PM3/24/10
to kryo-users
I'm trying to verify the impact(performance - storage, memory and
time) of Kryo vs Java serialization and writing some simple tests to
see how Kryo serialization works. The idea is to adopt it in our
project if suitable. I had registered the Date(util, sql), Timestamp,
BigInteger, BigDecimal classes. I'm using the ObjectBuffer for the
read/write from/to a io stream. I see that Kryo is failing to
a) Instantiate classes with no n-arg constructors case with
BigInteger, BigDecimal and Timestamp and
b) also it seems to have some issue instantiating classes with private
final and private static inner classes.
Shouldn't the Serializers be using getDeclaredField() as opposed to
getField() to be able to access all fields of a class without
restriction on access modifier?

The code snippets with the TestObject are provided below. Please
advise.

Regards,
-Prasad

public static Object readObjectFromStream(InputStream is) {
try {
ObjectBuffer objBuffer = new ObjectBuffer(KRYO, 1024,
32*1024);
return objBuffer.readClassAndObject(is);
} finally {
is.close();
}
}

public static void writeObjectToStream(Object object, OutputStream os)
{
try {
ObjectBuffer objBuffer = new ObjectBuffer(KRYO, 1024,
32*1024);
objBuffer.writeClassAndObject(os, object);
} finally {
os.close();
}
}

public class SerializableTestObject implements Serializable
{
private boolean valid = true;

private int id = Integer.MIN_VALUE;

private Long Id = Long.valueOf(Long.MAX_VALUE);

// private BigInteger ID = BigInteger.TEN;

private float value = Float.MIN_NORMAL;

private Double Value = Double.valueOf(Double.MIN_NORMAL);

// private BigDecimal VALUE = BigDecimal.TEN;

private Date date = new Date();

// private Timestamp time = new Timestamp(System.currentTimeMillis());

private TestCcy ccy = TestCcy.USD;

static enum TestCcy {
EUR,
GBP,
USD,
JPY,
INR
}

}

Nate

unread,
Mar 24, 2010, 6:51:06 PM3/24/10
to kryo-...@googlegroups.com
Hi Prasad,

I've adapted the code you posted as a unit test for ObjectBuffer in r81:
http://code.google.com/p/kryo/source/browse/trunk/test/com/esotericsoftware/kryo/serialize/ObjectBufferTest.java

Please see this issue for more information about serializing classes that do not have a zero argument constructor:
http://code.google.com/p/kryo/issues/detail?id=5&can=1

-Nate



--
You received this message because you are subscribed to the "kryo-users" group.
http://groups.google.com/group/kryo-users

To unsubscribe from this group, send email to kryo-users+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

Vootla

unread,
Mar 25, 2010, 4:46:19 PM3/25/10
to kryo-users
Hi Nate,

Thanks for the quick response. My browser thew an error while posting
and I had assumed the post didn't go through. Meanwhile, I figured
that Kryo comes with BigInteger and BigDecimal Serializers. I had also
written my own SqlDate, SqlTime, SqlTimestamp serializers.

Also, I have some question regarding overriding DefaultSerializer and
I'm posting it as a new thread to make the Subject clear.

Thanks,
-Prasad

On Mar 24, 6:51 pm, Nate <nathan.sw...@gmail.com> wrote:
> Hi Prasad,
>

> I've adapted the code you posted as a unit test for ObjectBuffer in r81:http://code.google.com/p/kryo/source/browse/trunk/test/com/esotericso...

Reply all
Reply to author
Forward
0 new messages