diff --git a/src/OrchardCore/OrchardCore.Abstractions/Json/JOptions.cs b/src/OrchardCore/OrchardCore.Abstractions/Json/JOptions.cs index 7fdb2854208..b7fe56c2c1e 100644 --- a/src/OrchardCore/OrchardCore.Abstractions/Json/JOptions.cs +++ b/src/OrchardCore/OrchardCore.Abstractions/Json/JOptions.cs @@ -13,7 +13,8 @@ public static class JOptions public static readonly JsonSerializerOptions Base = new() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, - ReferenceHandler = ReferenceHandler.IgnoreCycles, + PreferredObjectCreationHandling = JsonObjectCreationHandling.Populate, + ReferenceHandler = null, // Needed by JsonObjectCreationHandling.Populate. ReadCommentHandling = JsonCommentHandling.Skip, PropertyNameCaseInsensitive = true, AllowTrailingCommas = true, diff --git a/test/OrchardCore.Tests/Data/ContentItemTests.cs b/test/OrchardCore.Tests/Data/ContentItemTests.cs index c91f2ae3ea2..989e0603478 100644 --- a/test/OrchardCore.Tests/Data/ContentItemTests.cs +++ b/test/OrchardCore.Tests/Data/ContentItemTests.cs @@ -101,6 +101,23 @@ public void ContentShouldStoreFields() Assert.Contains(@"""MyPart"":{""Text"":""test"",""myField"":{""Value"":123}}", json); } + + [Fact] + public void ShouldDeserializeListContentPart() + { + var contentItem = new ContentItem(); + contentItem.GetOrCreate(); + contentItem.Alter(x => x.Text = "test"); + contentItem.Alter(x => + { + x.GetOrCreate("myField"); + x.Alter("myField", f => f.Value = 123); + }); + + var json = JConvert.SerializeObject(contentItem); + + Assert.Contains(@"""MyPart"":{""Text"":""test"",""myField"":{""Value"":123}}", json); + } } public class MyPart : ContentPart @@ -112,4 +129,9 @@ public class MyField : ContentField { public int Value { get; set; } } + + public class GetOnlyListPart : ContentPart + { + public IList Texts { get; } = new List(); + } }