Thursday, August 13, 2015

Java Serializable Objects Usage

In order to break down Class object into bytes steam, Java.Io.Serializable is used. Whenever you want to send data over network, make sure to check if your class is implementing Serializable or not. Some points to remember to get rid of Serializable related errors.

  • If there is any inner class, it must be declared Serializable.
  • If there is any member variable of class which you don't want to send (or make serializable), declare it TRANSIENT.
  • If there is any arraylist declard e.g. Obseravable List from FX Collections, then remember that this type of list is not serializable and it will create errors. Use Simple Array List instead of FX Collections Observable List.


Example :

public class Patent implements java.io.Serializable 
{
   public String name;
   public String address;
   public transient int CNIC;
   public int number;

}

No comments:

Post a Comment