Thursday, February 2, 2012

Simple Examples using Kryo for Serialization

Kryo is a fast and efficient way of Serialization in Java. Below are a couple of simple examples using Kryo.

Note: Since I am using a ByteBuffer to write and read, you must call flip() on the buffer before you de-serialize. The buffer keeps current position of the last byte, that position is used to write/read into the buffer. If you read without flip() the position will be current (until buffer limit). By calling flip(), you are resetting current position to the beginning of the buffer. Good explanation in the following blog.
  1. 2 Ways to do a simple String serialization/deserialization

  2. List Serialization

  3. Custom bean Serialization


  1. Hi Olga, I am having a hard time to get it right using v2 kryo. Are you using it ? can you provide some sample for v2 if not too much trouble.

  2. Hi Roy, I haven't tried with kryo v2. I'll take a look in try to post some examples. What issues are you having ?