What is Serialization?

JavaOopSerializationMarshalling

Java Problem Overview


I am getting started with Object-Oriented Programming (OOP) and would like to know: what is the meaning of serialization in OOP parlance?

Java Solutions


Solution 1 - Java

Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network.

Deserialization is the reverse process: turning a stream of bytes into an object in memory.

Solution 2 - Java

Simply speaking Serialization is a process of converting an Object into stream of bytes so that it can be transferred over a network or stored in a persistent storage.

Deserialization is the exact opposite - Fetch a stream of bytes from network or persistence storage and convert it back to the Object with the same state.

The thing to understand is how those stream of bytes are interpreted or manipulated so that we get the exact same Object/ same state. There are various ways to achieve that. Some of them are -

  1. XML: Convert Object to XML, transfer it over a network or store it in a file/db. Retrieve it and convert it back to the object with same state. In Java we use JAXB(Java architecture for XML binding) library.(From java 6 it comes bundled with JDK).
  2. JSON: Same can be done by converting the Object to JSON (JavaScript Object notation). Again there is GSON library that can be used for this.
  3. Or we can use the Serialization that is provided by the OOP language itself. For example, in Java you can serialize an Object my making it implement Serializable interface and writing to Object Stream.

Solution 3 - Java

What is Serialization?

Simple Explanation via Picture:

Rex, my dog, is serialised!

Summary:

Serialization means transforming something (e.g. my dog Rex) into a series of 1s and 0s - which can be transported over the phone line, stored in memory. My friends overseas can then translate those 1s and 0s back into a perfect representation of a puppy (de-serialization) so they can enjoy Rex's company.

Clarification of Analogy

Friends, this is an analogy. I don't think you can actually serialise a puppy LOL. You would serialise a data structure, or some other complex object. (I wrote this answer so you can understand the concept, in a fun way, in less 3 seconds, without breaking your head against a technical encyclopedic definition. But if you prefer one please check out: this Wikipedia link).

Solution 4 - Java

Check this out, this will give you a good explanation:

http://en.wikipedia.org/wiki/Serialization

I think the most common use of the term serialization has to do with converting a binary object into an XML (or other string) representation so that it can be stored in a database/file or sent across a network in a web service call. Deserialization is the reverse process - converting an XML/string back into an object.

EDIT: Another term you might come across is marshalling/unmarshalling. Marshalling is basically the same concept as serializing, and unmarshalling is the same as deserializing.

Solution 5 - Java

> 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. > > ... > > This illustration shows the overall process of serialization > > Overall process of serialization > > ... > > Through serialization, a developer can perform actions like sending the object to a remote application by means of a Web Service, passing an object from one domain to another, passing an object through a firewall as an XML string, or maintaining security or user-specific information across applications

From https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/serialization/

(emphasis mine)

Solution 6 - Java

Serialization is the process of converting unordered data (such as an object) into a series of tokens which can be used later to reconstruct the original data. The serialized form is most often a string of text, but doesn't have to be.

Solution 7 - Java

Serialization is the process of converting a Java,C# or any other (OOP languages) supported object to a transportable form. This way it be transported over the network or stored on a disk. For a class to be serializable, it must implement serializable interface.

Solution 8 - Java

serialization is converting an object to storable bit sequence.

so you can save this sequence to a file, db or send over network.

later you can deserialize it to the actual object and reuse it whenever you want.

Web Services and AJAX is the most common example of serialization. The objects serialized before sending the response to the client.

Solution 9 - Java

serialization is nothing but transfering the java supported object to file supported form

                         (OR)

converting java supported form to network supported form..the main scope of the serialization is nothing but to transfering the data from one layer to the another layer...only serialized objects we can send over the network..

Solution 10 - Java

When instantiating (constructing) the actual object(the thing) from a class (blueprint) there is a need to save the object (thing) by serializing it (breaking it down to its basic atomic structure) to a space in memory. (Kind of like Star Treks Transporter). You break the thing down into it stream of information that can be transported somewhere and stored. Then when you want to reconstruct the thing you just pull the atomically stored instance back into the object. Different from instaniation.

Solution 11 - Java

Serialization is turning data into a linear "string" of bytes.

Others have said more or less the same thing, but I stress that computer models require that data fits in the one-dimensionally addressed RAM or persistent storage.

Most things that are "data" are inherently serializable (even if you must reduce the abstract model to a linear one); not serializable are say a network connection or a complicated state-based machine like a parser.

Solution 12 - Java

serialization has to do with converting a binary object into an XML (or other string) representation so that it can be stored in a database/file or sent across a network in a web service call. Deserialization is the reverse process - converting an XML/string back into an object.

Solution 13 - Java

Serialization is the process of converting an object into binary data stream so that it can be stored in a file or send across a network where it can be resurrected back to the same object.

This document should help you understand Java serialization in detail.

Solution 14 - Java

Serialization is when object (a chunk of memory) translated in a form when object's state could be saved in file (as an example).

Just treat it as making cookies - object is a dough, cookie - is a serialized dough.

So by "serializing" you can send cookie to your friend.

Something like that :-)

Solution 15 - Java

simply just consider the following idea to understand it.

Serialization:

"hello world".split() returns ['hello', 'world']

De-serialization:

" ".join(['hello', 'world']) returns "hello world"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionedwardView Question on Stackoverflow
Solution 1 - JavaAndrew BarnettView Answer on Stackoverflow
Solution 2 - JavaAniket ThakurView Answer on Stackoverflow
Solution 3 - JavaBenKoshyView Answer on Stackoverflow
Solution 4 - JavaAndy WhiteView Answer on Stackoverflow
Solution 5 - JavaChamin WickramarathnaView Answer on Stackoverflow
Solution 6 - JavaDave SherohmanView Answer on Stackoverflow
Solution 7 - JavaNesan ManoView Answer on Stackoverflow
Solution 8 - JavaCanavarView Answer on Stackoverflow
Solution 9 - JavasriiiiView Answer on Stackoverflow
Solution 10 - JavaDavid K HillView Answer on Stackoverflow
Solution 11 - JavaOverflownView Answer on Stackoverflow
Solution 12 - JavaviswanathanView Answer on Stackoverflow
Solution 13 - JavaNikhil KatreView Answer on Stackoverflow
Solution 14 - JavaMr.ElectroNickView Answer on Stackoverflow
Solution 15 - JavaAkram NarejoView Answer on Stackoverflow