From b2e551a3c0ee38e0514ed15c9b64f628cc58861a Mon Sep 17 00:00:00 2001 From: CyberReiter Date: Thu, 27 Oct 2022 15:27:53 +0200 Subject: [PATCH] use System.Text.Json in ColorPickerValueConverter --- .../ColorPickerValueConverter.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs index 015f28b8eb5c..e228356c1762 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/ColorPickerValueConverter.cs @@ -1,8 +1,7 @@ // Copyright (c) Umbraco. // See LICENSE for more details. -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Text.Json; using Umbraco.Cms.Core.Models.PublishedContent; using Umbraco.Extensions; @@ -22,25 +21,28 @@ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType public override object? ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object? source, bool preview) { - var useLabel = UseLabel(propertyType); + bool useLabel = UseLabel(propertyType); if (source == null) { return useLabel ? null : string.Empty; } - var ssource = source.ToString()!; + string ssource = source.ToString()!; if (ssource.DetectIsJson()) { try { - JObject? jo = JsonConvert.DeserializeObject(ssource); - if (useLabel) + using (JsonDocument doc = JsonDocument.Parse(ssource)) { - return new PickedColor(jo!["value"]!.ToString(), jo["label"]!.ToString()); - } + JsonElement json = doc.RootElement; + if (useLabel) + { + return new PickedColor(json.GetProperty("value").GetString()!, json.GetProperty("label").GetString()!); + } - return jo!["value"]!.ToString(); + return json.GetProperty("value").GetString()!; + } } catch {