diff --git a/Emby.Server.Implementations/Plugins/PluginManager.cs b/Emby.Server.Implementations/Plugins/PluginManager.cs index 2497cddd9..b46c19995 100644 --- a/Emby.Server.Implementations/Plugins/PluginManager.cs +++ b/Emby.Server.Implementations/Plugins/PluginManager.cs @@ -9,6 +9,7 @@ using System.Text.Json; using MediaBrowser.Common; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Json; +using MediaBrowser.Common.Json.Converters; using MediaBrowser.Common.Plugins; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Plugins; @@ -50,6 +51,7 @@ namespace Emby.Server.Implementations.Plugins _pluginsPath = pluginsPath; _appVersion = appVersion ?? throw new ArgumentNullException(nameof(appVersion)); _jsonOptions = JsonDefaults.GetOptions(); + _jsonOptions.Converters.Add(new JsonGuidDashConverter()); _jsonOptions.WriteIndented = true; _config = config; _appHost = appHost; diff --git a/MediaBrowser.Common/Json/Converters/JsonGuidDashConverter.cs b/MediaBrowser.Common/Json/Converters/JsonGuidDashConverter.cs new file mode 100644 index 000000000..75bab5875 --- /dev/null +++ b/MediaBrowser.Common/Json/Converters/JsonGuidDashConverter.cs @@ -0,0 +1,26 @@ +using System; +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace MediaBrowser.Common.Json.Converters +{ + /// + /// Converts a GUID object or value to/from JSON. + /// + public class JsonGuidDashConverter : JsonConverter + { + /// + public override Guid Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + { + var guidStr = reader.GetString(); + return guidStr == null ? Guid.Empty : new Guid(guidStr); + } + + /// + public override void Write(Utf8JsonWriter writer, Guid value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.ToString()); + } + } +} diff --git a/MediaBrowser.Common/Plugins/PluginManifest.cs b/MediaBrowser.Common/Plugins/PluginManifest.cs index f93821429..956a91f85 100644 --- a/MediaBrowser.Common/Plugins/PluginManifest.cs +++ b/MediaBrowser.Common/Plugins/PluginManifest.cs @@ -1,6 +1,7 @@ #nullable enable using System; using System.Text.Json.Serialization; +using MediaBrowser.Common.Json.Converters; using MediaBrowser.Model.Plugins; namespace MediaBrowser.Common.Plugins @@ -32,6 +33,7 @@ namespace MediaBrowser.Common.Plugins /// Gets or sets the Global Unique Identifier for the plugin. /// [JsonPropertyName("guid")] + [JsonConverter(typeof(JsonGuidDashConverter))] public Guid Id { get; set; } ///