Avoid serializing empty collections

Serializing empty collections can be surprisingly wasteful! This post describes a technique which speeds up things and reduces the data size! And the principle behind this technique is simple: avoid serializing empty collections. If your objects contain many empty collections this can make a big difference as you’ll see. We’ll reduce the data size by more than 80% and requires 60% less time to serialized and deserialize for our simple example class. (more…)

Continue Reading

How Java serialization deserializes final fields

Implementing readObject() or readExternal() for immutable objects is a problem. We show how the JDK uses Unsafe to assign values to final fields.

Did you ever wondered how Java serialization can set final fields of your immutable classes? If not don’t worry, most Java developers never stopped to think about it. In this post we illustrate what the question is all about. And we tell you how the JDK serialization can ignore the fact that fields are declared final and still set their value during deserialization. Not only can it sets set field values, it does so efficiently. (more…)

Continue Reading
Close Menu