Sphyrnidae Common Library  2.0.1
Shared Utilities/Library
Serialize

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

  1. HealthCheck: Output of the health check is basically the serialized HealthReport
  2. Identity: Conversion between the identity and JWT
  3. Middleware exceptions will write out a custom response that is a serialized object
  4. Logging: Utilization of extension method ToNameValueCollection to basically convert a generic response object to something that is loggable
  5. DatabaseInformation (see Logging): Conversion of generic database parameters to something that can be logged
  6. Log4NetLogger (see Loggers): Log4Net only logs strings, so the object to be logged needs to be serialized
  7. 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>();