Skip to content

Commit de64c53

Browse files
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 <[email protected]>
1 parent d9e7e9e commit de64c53

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Umbraco.Core/PropertyEditors/PlainDateTimePropertyEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Umbraco.Cms.Core.PropertyEditors;
1313
public class PlainDateTimePropertyEditor : DataEditor
1414
{
1515
/// <summary>
16-
/// Initializes a new instance of the <see cref="PlainIntegerPropertyEditor" /> class.
16+
/// Initializes a new instance of the <see cref="PlainDateTimePropertyEditor" /> class.
1717
/// </summary>
1818
public PlainDateTimePropertyEditor(IDataValueEditorFactory dataValueEditorFactory)
1919
: base(dataValueEditorFactory)

src/Umbraco.Infrastructure/Serialization/JsonObjectConverter.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,15 @@ public override void Write(Utf8JsonWriter writer, object value, JsonSerializerOp
101101
JsonTokenType.Number when reader.TryGetInt32(out int i) => i,
102102
JsonTokenType.Number when reader.TryGetInt64(out long l) => l,
103103
JsonTokenType.Number => reader.GetDouble(),
104-
JsonTokenType.String when reader.TryGetDateTimeOffset(out DateTimeOffset datetime) => datetime,
105-
JsonTokenType.String when reader.TryGetDateTime(out DateTime datetime) => datetime,
104+
105+
// DateTime and DateTimeOffset are not handled here, as in doing so we would convert strings that look like dates into dates,
106+
// which, if coming fron a content property based on a text string property editor, isn't what we want.
107+
// The date picker property editors work with strings, so this is fine.
108+
// Testing also suggests other dates like for content content schedules aren't affected.
109+
// See:
110+
// - https://github.com/umbraco/Umbraco-CMS/issues/19360
111+
// - https://github.com/umbraco/Umbraco-CMS/pull/19807
112+
106113
JsonTokenType.String => reader.GetString(),
107114
_ => JsonDocument.ParseValue(ref reader).RootElement.Clone()
108115
};

0 commit comments

Comments
 (0)