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