Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are the disadvantages of making a class serializable in java [closed]

I want to know the disadvantages of making a class serializable in java;

disadvantages in terms of memory allocation and accessibility.

any link on this topic will be helpful

Thanks in advance.

like image 866
Swarnendu Paul Avatar asked Dec 05 '22 10:12

Swarnendu Paul


2 Answers

disadvantages in terms of memory allocation

Zero.

and accessibility

Zero. I don't understand the question but the answer is still zero.

If you don't want a specific class member to be serialized, you can always make it transient, which will save any serialization overhead connected with the class that contains that member.

The act of implements Serializable itself has zero negative consequences.

I don't know what you mean by 'safe', but using Serialization for deep copies certainly works.

like image 190
user207421 Avatar answered Dec 21 '22 23:12

user207421


If you look at Java and its session objects, pure object serialization is used.
Assuming that an application session is fairly short-lived, meaning at most a few hours, object serialization is simple, well supported and built into the Java concept of a session.
However, when the data persistence is over a longer period of time, possibly days or weeks, and you have to worry about new releases of the application, serialization quickly becomes evil.
As any good Java developer knows, if you plan to serialize an object, even in a session, you need a real serialization ID (serialVersionUID), not just a 1L, and you need to implement the Serializable interface.
However, most developers do not know the real rules behind the Java deserialization process.
If your object has changed, more than just adding simple fields to the object, it is possible that Java cannot deserialize the object correctly even if the serialization ID has not changed.
Suddenly, you cannot retrieve your data any longer, which is inherently bad.

Please visit https://softwareengineering.stackexchange.com/questions/191269/java-serialization-advantages-and-disadvantages-use-or-avoid

like image 25
Shreyos Adikari Avatar answered Dec 21 '22 23:12

Shreyos Adikari