Fix DataValueEditor incorrectly serializing JSON value (#12015)

* Remove JSON serialization

* Skip JSON serialization of strings
This commit is contained in:
Ronald Barendse
2022-02-17 13:33:45 +01:00
committed by GitHub
parent 76fc3f8201
commit 27a3431e76

View File

@@ -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
/// <exception cref="System.ArgumentOutOfRangeException">ValueType was out of range.</exception>
internal Attempt<object> 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;