What if a class is implementing serializable interface, but there's no writeObject/readObject
method implementation anywhere in the codebase?
Will the default methods defaultWriteObject/defaultReadObject
do the serialization or not?
Is only marking the class with implements Serializable
enough to serialize a class?
If yes, then what is getting serialized and where is the state of object getting persisted?
What if a class is implementing serializable interface, but there's no
writeObject/readObject
method implementation anywhere in the codebase?
It will be subject to default serialization: see below.
Will the default methods
defaultWriteObject/defaultReadObject
do the serialization or not?
No, because they won't be invoked unless you invoke them.
Is only marking the class with
implements Serializable
enough to serialize a class?
Yes, if you're content with default serialization: see below.
If yes, then what is getting serialized
All the non-transient non-static member variables of the class and all its base classes that implement Serializable,
and nothing else.
and where is the state of object getting persisted?
Into the stream. This part of your question doesn't seem to make sense,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With