How would you exclude a field of a class from serialization or what is a transient variable?

Transient variables cannot be serialized. The fields marked transient in a serializable object will not be transmitted in the byte stream. An example would be a file handle, a database connection, a system thread etc. Such objects are only meaningful locally. So they should be marked as transient in a serializable class.

Serialization can adversely affect performance since it:

  • Depends on reflection.
  • Has an incredibly verbose data format.
  • Is very easy to send surplus data.
Tagged . Bookmark the permalink.

Leave a Reply