The Serialization class is a collection of extension methods that allow you to de/serialize JSON or XML. The JSON methods take an optional parameter of JsonSerializerSettings - default is to specify DefaultValueHandling.IgnoreAndPopulate. You can specify any of the pre-configured SerializationSettings, or you can specify your own custom JsonSerializerSettings.
Where Used
- HealthCheck: Output of the health check is basically the serialized HealthReport
- Identity: Conversion between the identity and JWT
- Middleware exceptions will write out a custom response that is a serialized object
- Logging: Utilization of extension method ToNameValueCollection to basically convert a generic response object to something that is loggable
- DatabaseInformation (see Logging): Conversion of generic database parameters to something that can be logged
- Log4NetLogger (see Loggers): Log4Net only logs strings, so the object to be logged needs to be serialized
- WebServiceBase (see Web Services): Any data that is POST/PUT/etc needs to be serialized to the request body
Examples
var obj = new Foo();
var serialized = obj.SerializeJson();
obj = serialized.DeserializeJson<Foo>();
serialized = obj.SerializeXml();
obj = serialized.DeserializeXml<Foo>();