New json converter implemented.
This commit is contained in:
parent
7a66761981
commit
3633996a53
|
@ -9,6 +9,7 @@ using System.Text.Json;
|
||||||
using MediaBrowser.Common;
|
using MediaBrowser.Common;
|
||||||
using MediaBrowser.Common.Extensions;
|
using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Common.Json;
|
using MediaBrowser.Common.Json;
|
||||||
|
using MediaBrowser.Common.Json.Converters;
|
||||||
using MediaBrowser.Common.Plugins;
|
using MediaBrowser.Common.Plugins;
|
||||||
using MediaBrowser.Model.Configuration;
|
using MediaBrowser.Model.Configuration;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
|
@ -50,6 +51,7 @@ namespace Emby.Server.Implementations.Plugins
|
||||||
_pluginsPath = pluginsPath;
|
_pluginsPath = pluginsPath;
|
||||||
_appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion));
|
_appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion));
|
||||||
_jsonOptions = JsonDefaults.GetOptions();
|
_jsonOptions = JsonDefaults.GetOptions();
|
||||||
|
_jsonOptions.Converters.Add(new JsonGuidDashConverter());
|
||||||
_jsonOptions.WriteIndented = true;
|
_jsonOptions.WriteIndented = true;
|
||||||
_config = config;
|
_config = config;
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
|
|
26
MediaBrowser.Common/Json/Converters/JsonGuidDashConverter.cs
Normal file
26
MediaBrowser.Common/Json/Converters/JsonGuidDashConverter.cs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Common.Json.Converters
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a GUID object or value to/from JSON.
|
||||||
|
/// </summary>
|
||||||
|
public class JsonGuidDashConverter : JsonConverter<Guid>
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
var guidStr = reader.GetString();
|
||||||
|
return guidStr == null ? Guid.Empty : new Guid(guidStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options)
|
||||||
|
{
|
||||||
|
writer.WriteStringValue(value.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
using System;
|
using System;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using MediaBrowser.Common.Json.Converters;
|
||||||
using MediaBrowser.Model.Plugins;
|
using MediaBrowser.Model.Plugins;
|
||||||
|
|
||||||
namespace MediaBrowser.Common.Plugins
|
namespace MediaBrowser.Common.Plugins
|
||||||
|
@ -32,6 +33,7 @@ namespace MediaBrowser.Common.Plugins
|
||||||
/// Gets or sets the Global Unique Identifier for the plugin.
|
/// Gets or sets the Global Unique Identifier for the plugin.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonPropertyName("guid")]
|
[JsonPropertyName("guid")]
|
||||||
|
[JsonConverter(typeof(JsonGuidDashConverter))]
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user