Serializing Object Graphs as XML
Explore how to serialize and deserialize object graphs as XML in C#. Understand creating custom classes, using XmlSerializer, handling exceptions, and making XML more compact with attributes to save storage space.
An object graph is multiple objects related to each other either through a direct reference or indirectly through a chain of references.
Serialization
Serialization converts a live object graph into a sequence of bytes using a specified format. Deserialization is the reverse process.
We would do this to save the current state of a live object so that we can recreate it in the future, for example, saving the current state of a game so that we can continue at the same place tomorrow. Serialized objects are usually stored in a file or database. We can specify dozens of formats, but eXtensible Markup Language (XML) and JavaScript Object Notation (JSON) are the most common.
.NET has multiple classes that will serialize to and from XML and JSON. We will start by looking at XmlSerializer and JsonSerializer. ...