C# Interview Question #116
What is serialization in C#?
Concurrency, Performance & Design Senior Advanced
Quick Interview Answer
Serialization converts an object's data into a format suitable for storage or transmission, such as JSON. Deserialization reconstructs an object representation from that format.
Detailed Explanation
Serialization converts an object's data into a format suitable for storage or transmission, such as JSON. Deserialization reconstructs an object representation from that format.
System.Text.Json is the standard high-performance JSON library built into modern .NET. Serialization is widely used in web APIs, messaging, caching, configuration, and persistence.
Public API contracts should normally use dedicated DTOs rather than directly serializing database entities, which helps control security, compatibility, cycles, and exposed fields.
Code Example
var product = new ProductDto(1, "Laptop", 1200);
string json = JsonSerializer.Serialize(product);
ProductDto? restored =
JsonSerializer.Deserialize<ProductDto>(json);