Java

Topic: Serialization

 Can you Customize Serialization process or can you override default Serialization process in Java?

The answer is yes you can. We all know that for serializing an object ObjectOutputStream.writeObject (saveThisobject) is invoked and for reading object ObjectInputStream.readObject() is invoked but there is one more thing which Java Virtual Machine provides you is to define these two method in your class. If you define these two methods in your class then JVM will invoke these two methods instead of applying default serialization mechanism. You can customize behavior of object serialization and deserialization here by doing any kind of pre or post processing task. Important point to note is making these methods private to avoid being inherited, overridden or overloaded. Since only Java Virtual Machine can call private method integrity of your class will remain and Java Serialization will work as normal. In my opinion this is one of the best question one can ask in any Java Serialization interview, a good follow-up question is why should you provide custom serialized form for your object?

Browse random answers:

Define Serialization? What do you mean by Serialization in Java?
Why is Serialization required? What is the need to Serialize?
What is the Difference between Externalizable and Serializable Interfaces?
When will you use Serializable or Externalizable interface? and why?
What are the ways to speed up Object Serialization? How to improve Serialization performance?
What is a Serial Version UID (serialVersionUID) and why should I use it? How to generate one?
What would happen if the SerialVersionUID of an object is not defined?
Does setting the serialVersionUID class field improve Java serialization performance?
What are the alternatives to Serialization? If Serialization is not used, is it possible to persist or transfer an object using any other approach?
What are transient variables? What role do they play in Serialization process?
Why does serialization NOT save the value of static class attributes? Why static variables are not serialized?
How to Serialize a collection in java? How to serialize a ArrayList, Hashmap or Hashset object in Java?
Is it possible to customize the serialization process? How can we customize the Serialization process?
How can a sub-class of Serializable super class avoid serialization? If serializable interface is implemented by the super class of a class, how can the serialization of the class be avoided?
What changes are compatible and incompatible to the mechanism of java Serialization?
How to make a Java class Serializable?
How many methods Serializable has? If no method then what is the purpose of Serializable interface?
What is serialVersionUID? What would happen if you don't define this?
While serializing you want some of the members not to serialize? How do you achieve it?
 What will happen if one of the members in the class doesn't implement Serializable interface?
 If a class is Serializable but its super class in not, what will be the state of the instance variables inherited from super class after deserialization?
 Can you Customize Serialization process or can you override default Serialization process in Java?
 Suppose super class of a new class implement Serializable interface, how can you avoid new class to being serialized?
Which methods are used during Serialization and DeSerialization process in java?
Suppose you have a class which you serialized it and stored in persistence and later modified that class to add a new field. What will happen if you deserialize the object already serialized?
What are the compatible changes and incompatible changes in Java Serialization Mechanism?
Can we transfer a Serialized object vie network?
Which kind of variables is not serialized during Java Serialization?