Skip to content

Commit 27a3431

Browse files
Fix DataValueEditor incorrectly serializing JSON value (#12015)
* Remove JSON serialization * Skip JSON serialization of strings
1 parent 76fc3f8 commit 27a3431

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/Umbraco.Core/PropertyEditors/DataValueEditor.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Runtime.Serialization;
77
using System.Xml.Linq;
88
using Microsoft.Extensions.Logging;
9-
using Umbraco.Cms.Core.Hosting;
109
using Umbraco.Cms.Core.IO;
1110
using Umbraco.Cms.Core.Models;
1211
using Umbraco.Cms.Core.Models.Editors;
@@ -158,17 +157,15 @@ public IEnumerable<ValidationResult> Validate(object value, bool required, strin
158157
/// <exception cref="System.ArgumentOutOfRangeException">ValueType was out of range.</exception>
159158
internal Attempt<object> TryConvertValueToCrlType(object value)
160159
{
161-
// Ensure empty string values are converted to null
162-
if (value is string s && string.IsNullOrWhiteSpace(s))
160+
// Ensure empty string and JSON values are converted to null
161+
if (value is string stringValue && string.IsNullOrWhiteSpace(stringValue))
163162
{
164163
value = null;
165164
}
166-
167-
// Ensure JSON is serialized properly (without indentation or converted to null when empty)
168-
if (value is not null && ValueType.InvariantEquals(ValueTypes.Json))
165+
else if (value is not string && ValueType.InvariantEquals(ValueTypes.Json))
169166
{
167+
// Only serialize value when it's not already a string
170168
var jsonValue = _jsonSerializer.Serialize(value);
171-
172169
if (jsonValue.DetectIsEmptyJson())
173170
{
174171
value = null;

0 commit comments

Comments
 (0)