Find use of serialization

I support some kind of application, and I have a class marked as Serializable, but I suspect that it is not serialized anywhere, so the label is Serializablenot needed.

What is the best way to verify this? Can this be determined statically?

thank

+3
source share
3 answers

Not directly. Typically, serialization occurs when an object is written to ObjectOutputStream, but more often than not, it happens outside of your code (for example, in the libraries you use or in your container). So you have two options:

  • - . , , , , , . :

    private void writeObject(java.io.ObjectOutputStream out) {
       out.defaultWriteObject();
       log.info("Object of type " + 
          getClass().getName() + " is being serialized");
       // optionally include a stacktrace here, or use a debugger, to see
       // when exactly it happened
    }
    
  • , . (, ), Serializable. , , .

+3

, , , - - , ..

, / readResolve() writeReplace(), jvm, /.

+1

, , , ( )

Perhaps you are using some kind of ORM, such as Hibernate, which in some cases should have a serializable object, or your object should be sent via the Web-Service or other middleware stacks like Corba where serialization is done implicitly (when the object marked as such).

What is the purpose of your class?

0
source

Source: https://habr.com/ru/post/1782283/


All Articles