Solve Not Serializable Exception
If you try to serialize an object of a class which implements Serializable, but the object includes a reference to an non- Serializable class then a ‘NotSerializableException’ will be thrown at runtime.
The simplest way is to find the class that throws the exception and make it implement the Serializable interface. However, this may not be feasible if the class that throws the exception belongs to a third-party library i.e. org.apache.log4j.Logger.
In case the class refers to non-serializable objects and these objects should not be serialized, then, you can declare these objects as transient. Once a field of a class is declared as transient, then, it is ignored by the serializable runtime.
Fix java.io.NotSerializableException in org.apache.log4j.Logger
org.apache.log4j.Logger is simple, you have to prevent logger instance from default serializabtion process, either make it transient or static.
Making it transient after deserialization logger instance will be null and any logger.debug() call will result in NullPointerException.
By making it static and final you ensure that its thread-safe and all instance of Employee class can share same logger instance.