Is it possible to serialize transient field of the class using my custom serialization or using Externalization?
Example: there is a class Person
having name field transient
transient String name;
Is it possible to serialize it using below methods?
private void writeObject(ObjectOutputStream out) throws IOException;
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException;
The answer is yes if you are using the custom serializaton. When we do custom serialization by overriding the
writeObject
method, you take control of the serialization and can do whatever you want. So you can also assign or use a value of atransient
field and can also marshall it along with other class attributes.