Skip to content
Aleksandr Kuchuk edited this page May 9, 2016 · 29 revisions

About

A lot of people think that serialization is quite simple - all that we do is implement java.io.Serializable interface.

Yes, in simple - it's all that we need, but what about different finer points? How many ways are there to serialize object? One? Two? The right answer is - two ways! We can:

  • implements java.io.Serializable
  • implements Externalizable

Let's talk about it more detail!

Serializable interface

Standart serialization in Java works by Reflection API, class puzzle out for the fields and writes to the output. And ofcourse if we use reflection - it's not optimize. And another one - when we use standart serialization we don't call constructor of the class in deserialization, we stand memory for the class and after that all class fields fill by values from stream(input). We don't call constructor!

And what about parent class? If our class is serializable, what about parent class? Parent class isn't serializable! When we deserialize our class - we call constructor without parameters! And we don't call constructor of class which we try to deserialize. If we havn't got this constructor - we catch an error.

Externalizable

todo

Clone this wiki locally