Serialization

[1] When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object.

[2][3][4] The opposite operation, extracting a data structure from a series of bytes, is deserialization, (also called unserialization or unmarshalling).

For example, for maximal use of distribution, a computer running on a different hardware architecture should be able to reliably reconstruct a serialized data stream, regardless of endianness.

This means that the simpler and faster procedure of directly copying the memory layout of the data structure cannot work reliably for all architectures.

In many applications, this linearity is an asset, because it enables simple, common I/O interfaces to be utilized to hold and pass on the state of an object.

In applications where higher performance is an issue, it can make sense to expend more effort to deal with a more complex, non-linear storage organization.

This is useful in the programming of user interfaces whose contents are time-varying — graphical objects can be created, removed, altered, or made to handle input events without necessarily having to write separate code to do those things.

Serialization breaks the opacity of an abstract data type by potentially exposing private implementation details.

[5] To discourage competitors from making compatible products, publishers of proprietary software often keep the details of their programs' serialization formats a trade secret.

Many institutions, such as archives and libraries, attempt to future proof their backup archives—in particular, database dumps—by storing them in some relatively human-readable serialized format.

In the late 1990s, a push to provide an alternative to the standard serialization protocols started: XML, an SGML subset, was used to produce a human-readable text-based encoding.

It has the disadvantage of losing the more compact, byte-stream-based encoding, but by this point larger storage and transmission capacities made file size less of a concern than in the early days of computing.

In the 2000s, XML was often used for asynchronous transfer of structured data between client and server in Ajax web applications.

Property list, or p-list for short, doesn't refer to a single serialization format but instead several different variants, some human-readable and one binary.

For large volume scientific datasets, such as satellite data and output of numerical climate, weather, or ocean models, specific binary serialization standards have been developed, e.g. HDF, netCDF and the older GRIB.

Moreover, compiler-based solutions, such as the ODB ORM system for C++ and the gSOAP toolkit for C and C++, are capable of automatically producing serialization code with few or no modifications to class declarations.

CFML allows data structures to be serialized to WDDX with the tag and to JSON with the SerializeJSON() function.

Delphi provides a built-in mechanism for serialization of components (also called persistent objects), which is fully integrated with its IDE.

[15]: 339–345  The standard encoding method uses a recursive graph-based translation of the object's class descriptor and serializable fields into a byte stream.

[16] While Swing components do implement the Serializable interface, they are not guaranteed to be portable between different versions of the Java Virtual Machine.

A file containing lisp code may be read into memory as a data structure, transformed by another program, then possibly executed or written out, such as in a read–eval–print loop.

When serializing structures with Storable, there are network safe functions that always store their data in a format that is readable on any computer at a small cost of speed.

In practice, implementation-specific extensions (e.g. SWI-Prolog's dictionaries) may use non-standard term structures, so interoperability may break in edge cases.

[32] Whether and how serialized terms received over the network are checked against a specification (after deserialization from the character stream has happened) is left to the implementer.

Finally, it is recommended that an object's __repr__ be evaluable in the right environment, making it a rough match for Common Lisp's print-object.

In general, non-recursive and non-sharing objects can be stored and retrieved in a human readable form using the storeOn:/readFrom: protocol.

The storeOn: method generates the text of a Smalltalk expression which – when evaluated using readFrom: – recreates the original object.

Both provide a so-called "binary-object storage framework", which support serialization into and retrieval from a compact binary form.

The Swift standard library provides two protocols, Encodable and Decodable (composed together as Codable), which allow instances of conforming types to be serialized to or deserialized from JSON, property lists, or other formats.

Two dimensional data structures can also be (de)serialized in CSV format using the built-in cmdlets Import-CSV and Export-CSV.

Flow diagram
Our example struct Point implements the Serialize and Deserialize traits