Is serialization independent of methods?

I have two classes: one on the server and one on the client application, which have the same fields and constructors, but different methods. (in particular, the server class has setters, while the client side does not)

I read about Oracle docs that the interface Serializableallows me to save the state of an object and, as I understand it, it packs the fields during serialization and rebuilds the object during deserialization.

It’s not clear to me whether I need an exact copy of the class or whether these methods are not important for serialization, and I can use 2 different classes with the same fields and constructors.

+4
source share
2 answers

- , (Java 8), , , - , :

  • writeObject readObject
  • writeReplace readResolve

, . , , .

: Java, UID . ?

:, , , , , serialVersionUID, . , , UID. serialVersionUID , , , UID (.. , , ), .

2: Java- , , Java 8, , , serialVersionUID . , / , / . , , .

+2

. (, , ), . !

XStreams. , .

-1

All Articles