Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kawodyaarachchige/serialisation-deserialisation

Technical Description Based on Research & Development (AAD)
https://github.com/kawodyaarachchige/serialisation-deserialisation

Last synced: 8 days ago
JSON representation

Technical Description Based on Research & Development (AAD)

Awesome Lists containing this project

README

        

# Serialization and Deserialization process

## Introduction
Java's serialization feature plays a crucial role in converting an object's state into a byte stream, a necessity for scenarios involving object persistence, such as saving states to disk for later use, or sending objects over networks for reconstruction in another JVM. Deserialization, the reverse process, transforms the byte stream back into a fully operational object, ensuring the application state remains consistent and uninterrupted.

## Augmented Benefits

### Persistence:
Serialization isn't limited to merely storing objects on disk; it supports the preservation of complex object hierarchies, allowing applications to retain their entire state or selected segments. This is especially important for applications that operate offline or those that restart without data loss.

### Streamlined Communication:
In the realm of distributed systems, serialization enables the streamlined transmission of objects across network interfaces. By encoding objects into compact byte streams, applications can efficiently exchange intricate data structures, reducing bandwidth needs and boosting performance.

### State Reinstatement:
Serialization provides a solid foundation for reinstating application states, enabling applications to continue exactly from where they were interrupted. This feature is particularly beneficial during software updates, system crashes, or when transitioning user sessions across servers.

## Comprehensive Mechanism

Java implements serialization via the Serializable interface, marking eligible classes for serialization. During serialization, the Java runtime uses reflection to examine the object's fields, translating their values into a byte stream. This stream can then be channeled to any output stream, such as a file or network socket.

Deserialization involves reading the byte stream and reconstructing the object, field by field, according to the information encapsulated within the stream. Successful deserialization requires the class definition of the serialized object to be present in the JVM performing the operation.

It's important to remember that serialization isn't enabled by default for all objects. Classes must explicitly declare the Serializable interface to allow their instances to be serialized. Developers also gain control over the serialization process through methods such as `writeObject()` and `readObject()`, enabling customization of serialization and deserialization practices.

### Integration of JSON with YAsson's JsonbBuilder
YAsson's `JsonbBuilder` provides a straightforward API for JSON binding, leveraging annotations to map Java objects to JSON and JSON to Java objects. This integration enhances the serialization and deserialization mechanism by offering a more readable and structured format, especially beneficial for web APIs and data storage.

## Summry

To summarize, serialization and deserialization in Java offer a powerful toolset for preserving object states and enhancing communication between distributed components. Proficiency in these processes is key to developing robust, scalable, and effective Java applications.