0% found this document useful (0 votes)
16 views3 pages

BSCS-Visu Prog (Serialization)

Serialization is the process of converting an object into a stream of bytes for storage or transmission, allowing the object's state to be saved and recreated. It includes methods such as JSON, binary, and XML serialization, each with specific use cases and requirements. Designer serialization is a specialized form used in development tools to persist object graphs into source files.

Uploaded by

Ch Uzair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

BSCS-Visu Prog (Serialization)

Serialization is the process of converting an object into a stream of bytes for storage or transmission, allowing the object's state to be saved and recreated. It includes methods such as JSON, binary, and XML serialization, each with specific use cases and requirements. Designer serialization is a specialized form used in development tools to persist object graphs into source files.

Uploaded by

Ch Uzair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

BSCS

Subject: Visual Programming


Semester 5th Lecture #
Date: /03/2025 Final Term
 Topic: Serialization
Serialization – Definition
Serialization is the process of converting an object into a stream of bytes in order
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.

How Serialization Works

This illustration shows the overall process of serialization.

The object is serialized to a stream, which carries not just the data, but
information about the object's type, such as its version, culture, and assembly
name. From that stream, it can be stored in a database, a file, or memory.
Uses for Serialization

Serialization allows the developer to save the state of an object and recreate it as
needed, providing storage of objects as well as data exchange. 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.

JSON serialization

The System.Text.Json namespace contains classes for JavaScript Object Notation


(JSON) serialization and deserialization. JSON is an open standard that is
commonly used for sharing data across the web.

JSON serialization serializes the public properties of an object into a string, byte
array, or stream that conforms to the RFC 8259 JSON specification. To control the
way JsonSerializer serializes or deserializes an instance of the class, you can use
one or more of the following approaches:

 Use a JsonSerializerOptions object


 Apply attributes from the System.Text.Json. Serialization namespace to
classes or properties
 Customize the contract
 Implement custom converters

Making an Object Serializable

To serialize an object using binary or XML serialization, you need the object to
serialize, a stream to contain the serialized object, and
a Formatter. System.Runtime.Serialization contains the classes necessary for
serializing and desterilizing objects.

Apply the Serializable Attribute attribute to a type to indicate that instances of


this type can be serialized. A Serialization Exception exception is thrown if you
attempt to serialize but the type does not have the Serializable
Attribute attribute.
Binary Serialization

Binary serialization uses binary encoding to produce compact serialization for


uses such as storage or socket-based network streams.

XML Serialization

XML serialization serializes the public fields and properties of an object, or the
parameters and return values of methods, into an XML stream that conforms to a
specific XML Schema definition language (XSD) document. XML serialization
results in strongly typed classes with public properties and fields that are
converted to XML. System.Xml.Serialization contains the classes necessary for
serializing and desterilizing XML.

Basic and Custom Serialization

Binary and XML serialization can be performed in two ways, basic and custom.
Basic serialization uses .NET to automatically serialize the object.

The only requirement in basic serialization is that the object has the Serializable
Attribute attribute applied. The NonSerializedAttribute can be used to keep
specific fields from being serialized.

When you use basic serialization, the versioning of objects may create problems,
in which case custom serialization may be preferable. Basic serialization is the
easiest way to perform serialization, but it does not provide much control over
the process.

Designer Serialization

Designer serialization is a special form of serialization that involves the kind of


object persistence usually associated with development tools. Designer
serialization is the process of converting an object graph into a source file that can
later be used to recover the object graph. A source file can contain code, markup,
or even SQL table information.

You might also like