Site icon

What is serialization & deserialization process in java (example)

1. Background of Serialization & Deserialization process:

Before we start our discussion about the Serialization and Deserialization, We will discuss one small concept, which we have studied in our academics. We know that all the high level languages (Java, C++, C etc) translated to low level or machine level language (i.e. Binary Code of 0 or 1). The compiler comes into play which actually performs this translation.
Why this translation was required? Our Machines like Computer or Server or Client understands one and only one language which is binary language. So, if we would like to instruct our machine to perform any kind of operation(s), then we need to request him (machine) in binary language.We can thought of Serializations on the same line. It is more or less similar concept, where in we translate one form into another form.

2. Application of Serialization & Deserialization:

  1. Serialization & Derialization is extensively used in Client Server paradigm.
    • e.g. Web Client to Web Service communication like Object to JSON/XML serialization.
  2. Serialization used in standalone systems.
    1. e.g. Save objects in memory to flat or text file.
    2. Load objects from flat file or text file.

3. Serialization & Deserialization in client server paradigm:

We will discuss serialization & deserialization process in context of client server paradigm. We will take an example of typical web applications. How web client can able to communicate with web servers ?
  1. Web client wants to send data to server.
    • e.g. In chrome or IE browser when we enter any URL like www.google.com.
  2. Web client will send request to web server.
    • Web client prepare the HTTP request.
    • Web client will serialize request.
  3. Web Server receive the HTTP request like GET, POST, PUT or DELET etc.
    • Web Server receive HTTP requests.
    • Web Server deserialize the HTTP requests.
  4. Web server process the request.
  5. Web Server prepares the HTTP response & sends back to response to web client.
    • Web server prepare HTTP response & serialize response.
  6. Web Client receives the response of Web server.
    • Web client deserialize the response & render on browser.

Typical scenario, (Web Client, Mobile Client or Window Client) sends request over the internet to the Server (like G-Mail, Google Docs, Google Analytic Server).

 

Fig 1: Typical Client Server paradigm

4. Example of Serialization & Deserialization process:

  • Web portal of university having Students, Teachers and Admin staff section.
  • Suppose, admin wants to save or export data of meritorious students of a particular year.
    • Admin needs to serialize the student data to flat or text or xml file.
    • Admin will perform following steps:
      • Translate the Objects to binary data.
      • Save the binary data to a flat/text/ xml file.
  • This process of saving the Objects to corresponding data store is called serialization.
Fig 2: University Application Containing different object
 Suppose, latter on admin wants to view saved data in web port, then admin needs to perform following operation i.e. opposite of Serialization process.
  1. Read the data from a file (text/xml file).
  2. Translate the binary data to corresponding objects.

The process of loading or populated objects from saved data is known as deserialization.

Serialization and Deserialization process is backbone of distributed computing systems, which enables the distributed components to communicate over the network.

Exit mobile version