aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Entities/JsonLowerCaseConverter.cs
blob: 7c627f0e39e10460a474597478f1838b008577db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#nullable disable
// THIS IS A HACK
// TODO: @bond Move to separate project

using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace MediaBrowser.Model.Entities
{
    /// <summary>
    /// Converts an object to a lowercase string.
    /// </summary>
    /// <typeparam name="T">The object type.</typeparam>
    public class JsonLowerCaseConverter<T> : JsonConverter<T>
    {
        /// <inheritdoc />
        public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            return JsonSerializer.Deserialize<T>(ref reader, options);
        }

        /// <inheritdoc />
        public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
        {
            writer.WriteStringValue(value?.ToString().ToLowerInvariant());
        }
    }
}