From de64c537770649247a8b70c0c1c0dfcc3ce7e290 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Fri, 1 Aug 2025 13:27:05 +0200 Subject: [PATCH] Omit datetime from JSON conversion that converts from strings (#19807) * Remove date object conversion as valueEditors don't seem to need it * Update fault summary reference * Added justification comment. --------- Co-authored-by: Andy Butland --- .../PropertyEditors/PlainDateTimePropertyEditor.cs | 2 +- .../Serialization/JsonObjectConverter.cs | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Umbraco.Core/PropertyEditors/PlainDateTimePropertyEditor.cs b/src/Umbraco.Core/PropertyEditors/PlainDateTimePropertyEditor.cs index 0bc559972e..737f5b4db2 100644 --- a/src/Umbraco.Core/PropertyEditors/PlainDateTimePropertyEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/PlainDateTimePropertyEditor.cs @@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.PropertyEditors; public class PlainDateTimePropertyEditor : DataEditor { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public PlainDateTimePropertyEditor(IDataValueEditorFactory dataValueEditorFactory) : base(dataValueEditorFactory) diff --git a/src/Umbraco.Infrastructure/Serialization/JsonObjectConverter.cs b/src/Umbraco.Infrastructure/Serialization/JsonObjectConverter.cs index d8c9778461..0fc0aefd7d 100644 --- a/src/Umbraco.Infrastructure/Serialization/JsonObjectConverter.cs +++ b/src/Umbraco.Infrastructure/Serialization/JsonObjectConverter.cs @@ -101,8 +101,15 @@ public sealed class JsonObjectConverter : JsonConverter JsonTokenType.Number when reader.TryGetInt32(out int i) => i, JsonTokenType.Number when reader.TryGetInt64(out long l) => l, JsonTokenType.Number => reader.GetDouble(), - JsonTokenType.String when reader.TryGetDateTimeOffset(out DateTimeOffset datetime) => datetime, - JsonTokenType.String when reader.TryGetDateTime(out DateTime datetime) => datetime, + + // DateTime and DateTimeOffset are not handled here, as in doing so we would convert strings that look like dates into dates, + // which, if coming fron a content property based on a text string property editor, isn't what we want. + // The date picker property editors work with strings, so this is fine. + // Testing also suggests other dates like for content content schedules aren't affected. + // See: + // - https://github.com/umbraco/Umbraco-CMS/issues/19360 + // - https://github.com/umbraco/Umbraco-CMS/pull/19807 + JsonTokenType.String => reader.GetString(), _ => JsonDocument.ParseValue(ref reader).RootElement.Clone() };