Merge pull request #5407 from Bond-009/hack

(cherry picked from commit 90cdd1345d)
Signed-off-by: Joshua M. Boniface <joshua@boniface.me>
This commit is contained in:
Claus Vium
2021-03-08 21:23:14 +01:00
committed by Joshua M. Boniface
parent 3c3b536e81
commit f6e8493d69
4 changed files with 103 additions and 2 deletions

View File

@@ -0,0 +1,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());
}
}
}

View File

@@ -2,6 +2,7 @@
#pragma warning disable CS1591
using System;
using System.Text.Json.Serialization;
using MediaBrowser.Model.Configuration;
namespace MediaBrowser.Model.Entities
@@ -27,6 +28,7 @@ namespace MediaBrowser.Model.Entities
/// Gets or sets the type of the collection.
/// </summary>
/// <value>The type of the collection.</value>
[JsonConverter(typeof(JsonLowerCaseConverter<CollectionTypeOptions?>))]
public CollectionTypeOptions? CollectionType { get; set; }
public LibraryOptions LibraryOptions { get; set; }