Chapter 25 Serialization

What’s in This Chapter

  • Serialization and deserialization
  • XML, JSON, and binary serialization
  • Using attributes to control serialization Downloads for This Chapter

Please note that all the code examples for this chapter are available as a part of this chapter’s code download on the book’s website at on the Download Code tab.

Serialization is the process of converting one or more objects into a serial, stream-like format, often text. Deserialization is the reverse: restoring an object from its serialization.

Like the XML files described in the preceding chapter, serialization gives you a portable way to store data. You can serialize an object and send the serialization to another program, and then that program can deserialize the object.

You can also use serialization to allow a program to save and restore its state. For example, a drawing program might build a complicated data structure containing the objects the user drew. To save the drawing, the program could write the data structure’s serialization into a file. Later it could reload the serialization and display the objects.

The objects serialized can be relatively simple, such as a Customer or Person object, or they can be complex data structures including objects that have references to other objects. For example, you could serialize a CustomerOrder object that includes an array of Order objects each containing a list of OrderItem objects.

For something ...

Get C# 5.0 Programmer's Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.