mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-17 19:54:47 +01:00
Add number to bool json converter
This commit is contained in:
23
tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs
Normal file
23
tests/Jellyfin.Common.Tests/Json/JsonBoolNumberTests.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Text.Json;
|
||||
using Jellyfin.Common.Tests.Models;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Common.Tests.Json
|
||||
{
|
||||
public static class JsonBoolNumberTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("1", true)]
|
||||
[InlineData("0", false)]
|
||||
[InlineData("2", true)]
|
||||
[InlineData("true", true)]
|
||||
[InlineData("false", false)]
|
||||
public static void Deserialize_Number_Valid_Success(string input, bool? output)
|
||||
{
|
||||
var inputJson = $"{{ \"Value\": {input} }}";
|
||||
var options = new JsonSerializerOptions();
|
||||
var value = JsonSerializer.Deserialize<BoolTypeModel>(inputJson, options);
|
||||
Assert.Equal(value?.Value, output);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
tests/Jellyfin.Common.Tests/Models/BoolTypeModel.cs
Normal file
17
tests/Jellyfin.Common.Tests/Models/BoolTypeModel.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using MediaBrowser.Common.Json.Converters;
|
||||
|
||||
namespace Jellyfin.Common.Tests.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// The bool type model.
|
||||
/// </summary>
|
||||
public class BoolTypeModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the value is true or false.
|
||||
/// </summary>
|
||||
[JsonConverter(typeof(JsonBoolNumberConverter))]
|
||||
public bool Value { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user