When i define a java object to implement serializable interface, do the members of the object, also become serializable? Or i have to go as far along the nesting depth, to redefine every object along the path as serializable?
Serialization in Java is the process of converting the Java code Object into a Byte Stream, to transfer the Object Code from one Java Virtual machine to another and recreate it using the process of Deserialization.
Serialization is the process of converting an object into a stream of bytes to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.
Serializable interface. Serializable is a marker interface (has no data member and method). It is used to “mark” java classes so that objects of these classes may get certain capability. Other examples of marker interfaces are:- Cloneable and Remote.
Serialization in Java is a mechanism of writing the state of an object into a byte-stream. It is mainly used in Hibernate, RMI, JPA, EJB and JMS technologies. The reverse operation of serialization is called deserialization where byte-stream is converted into an object.
Most classes that you use regularly in java are serializable (Collections, String, decedents of Number, etc.), however any classes that you reference either have to be serializable or declared transient. Of course, if they are transient, they won't be referenced when the class is deserialized.
Well, implementing Serializable will give you serialization support only if all non-transient members (thanks, danben) are either primitives or serializable classes themselves.
So yes, if you have a lot of different things as members that are not serializable, then you have to make them serializable too.
Unless they are not important for representing your object's state. If you can re-create it without them, then you can always make the members transient to omit them from serialization.
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