From 27a3431e766f4f8b4bbe1bfbc69daa85d10abc38 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Thu, 17 Feb 2022 13:33:45 +0100 Subject: [PATCH] Fix DataValueEditor incorrectly serializing JSON value (#12015) * Remove JSON serialization * Skip JSON serialization of strings --- src/Umbraco.Core/PropertyEditors/DataValueEditor.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index 6f9e1b6611..795d75c319 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Runtime.Serialization; using System.Xml.Linq; using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.IO; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Editors; @@ -158,17 +157,15 @@ namespace Umbraco.Cms.Core.PropertyEditors /// ValueType was out of range. internal Attempt TryConvertValueToCrlType(object value) { - // Ensure empty string values are converted to null - if (value is string s && string.IsNullOrWhiteSpace(s)) + // Ensure empty string and JSON values are converted to null + if (value is string stringValue && string.IsNullOrWhiteSpace(stringValue)) { value = null; } - - // Ensure JSON is serialized properly (without indentation or converted to null when empty) - if (value is not null && ValueType.InvariantEquals(ValueTypes.Json)) + else if (value is not string && ValueType.InvariantEquals(ValueTypes.Json)) { + // Only serialize value when it's not already a string var jsonValue = _jsonSerializer.Serialize(value); - if (jsonValue.DetectIsEmptyJson()) { value = null;