Serializability Test in Java

Oracle Java

Previously I shared you about how to debug Java object with reflection, this article will also show you something about object in Java.

Long time back, I have an experience in solving problem related to clustering on production. This is actually troublesome, because I have to find what is the root cause of this. If you familiar with clustered environment, you should know about how the application server can do failover the system from one server to other server. And this is not always about environment settings, but also about the quality of application. Good application is clusterable, meaning they can be installed as standalone in single server or clustered environment with multi servers.

One of good point I realized during my experience here is how to guarantee all domain objects used in the system is serializable. Let say, you create a class which implement Serializable interface, it doesn’t mean serializable class. You must try this class in serialization process. Here I will show you the base unit test class (abstract class) which can be used to test for serializability of classes that you created, check it out.

Next question, how to use above class?

The simple way to use it is by using unit test as you can find below:

Execute with JUnit, and you will get the result. It’s really simple but not all developers aware of this, they usually do as fast as they can, without thinking about quality.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*