JsonGuidConverter.cs 647 B

1234567891011121314151617181920
  1. using System;
  2. using System.Text.Json;
  3. using System.Text.Json.Serialization;
  4. namespace MediaBrowser.Common.Json.Converters
  5. {
  6. /// <summary>
  7. /// Converts a GUID object or value to/from JSON.
  8. /// </summary>
  9. public class JsonGuidConverter : JsonConverter<Guid>
  10. {
  11. /// <inheritdoc />
  12. public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
  13. => new Guid(reader.GetString());
  14. /// <inheritdoc />
  15. public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
  16. => writer.WriteStringValue(value);
  17. }
  18. }