I’m mantaining some application and I have a class marked as Serializable but I suspect that is not being serialized anywhere so the Serializable mark is not needed.
What is the best way to be sure of that? It’s possible to determine this statically?
Thanks
Not directly. Generally, serialization happens when the object is being written to
ObjectOutputStream, but this most often happen outside of your code (for example in libraries you are using, or in your container). So you have two options:dynamically – define this method on your class. Thus you will eventually know if the class is being serialized, without breaking any functionality. But you’d need the system to be running:
try to understand where is your object going. If it transferred over a network, or stored in a temporary storage (session, cache), then it should be Serializable. Otherwise, most probably, not.