top of page
back.jpg

Serialization vs Deserialization




Serialization

Deserialization

  ObjectOutputStream class is used to serialize an object to a byte stream.

ObjectInputStream class is used to deserialize a byte stream into an object

Commonly used for saving object states persistently, transmitting objects over a network, or sharing data between different applications.

Crucial for scenarios where data, previously serialized, needs to be retrieved and used in its original object form. Common use cases include reading objects from files, receiving serialized data over a network, or reconstructing objects stored in databases.

Object to Byte Stream Example

// Serialize an object to a byte stream
ByteArrayOutputStream bytArrOPStream = new ByteArrayOutputStream();
ObjectOutputStream objOPStream = new bjectOutputStream(bytArrOPStream);

// Example object to be serialized
MyObject myObject = new MyObject();

// Serialize the object
objOPStream.writeObject(myObject);

// Get the byte stream
byte[] byteStream = bytArrOPStream.toByteArray();

// Close streams
objOPStream.close();
bytArrOPStream.close();

Byte Stream to Object Example

// Deserialize an object from a byte stream
ByteArrayInputStream bytArrIPStream = new ByteArrayInputStream(byteStream);
ObjectInputStream objIPStream = new ObjectInputStream(bytArrIPStream);

// Deserialize the object
MyObject deserializedObject = (MyObject) objIPStream.readObject();

// Close streams
objectInputStream.close();
bytArrIPStream.close();

3 views0 comments

Recent Posts

See All

Test case for Valid Coupon Code

This test case checks whether a valid coupon code is successfully applied to a booking cart, the total is updated accordingly, and a success message is displayed. package com.seleniumExamples2024; pu

Keyboard shortcut keys for various operations

General Shortcuts: Ctrl + C: Copy Ctrl + X: Cut Ctrl + V: Paste Ctrl + Z: Undo Ctrl + Y: Redo Ctrl + A: Select All Ctrl + S: Save Ctrl + P: Print Ctrl + F: Find Windows Shortcuts: Windows Key: Open or

What is Flaky test? Steps to resolve Test Flakiness

A flaky test An automated test in a software testing environment that may produce inconsistent results, sometimes passing and sometimes failing, even when applied to the same version of the software u

Comentarios

Obtuvo 0 de 5 estrellas.
Aún no hay calificaciones

Agrega una calificación
bottom of page