2
0

JsonLowerCaseConverter.cs 862 B

1234567891011121314151617181920212223242526272829
  1. #nullable disable
  2. // THIS IS A HACK
  3. // TODO: @bond Move to separate project
  4. using System;
  5. using System.Text.Json;
  6. using System.Text.Json.Serialization;
  7. namespace MediaBrowser.Model.Entities
  8. {
  9. /// <summary>
  10. /// Converts an object to a lowercase string.
  11. /// </summary>
  12. /// <typeparam name="T">The object type.</typeparam>
  13. public class JsonLowerCaseConverter<T> : JsonConverter<T>
  14. {
  15. /// <inheritdoc />
  16. public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
  17. {
  18. return JsonSerializer.Deserialize<T>(ref reader, options);
  19. }
  20. /// <inheritdoc />
  21. public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
  22. {
  23. writer.WriteStringValue(value?.ToString().ToLowerInvariant());
  24. }
  25. }
  26. }