Skip to content

Commit

Permalink
Update JOptions configuration (Lombiq Technologies: OCORE-149) (#15534)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Mar 21, 2024
1 parent 28bd184 commit 7326e8c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/OrchardCore/OrchardCore.Abstractions/Json/JOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions test/OrchardCore.Tests/Data/ContentItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetOnlyListPart>();
contentItem.Alter<MyPart>(x => x.Text = "test");
contentItem.Alter<MyPart>(x =>
{
x.GetOrCreate<MyField>("myField");
x.Alter<MyField>("myField", f => f.Value = 123);
});

var json = JConvert.SerializeObject(contentItem);

Assert.Contains(@"""MyPart"":{""Text"":""test"",""myField"":{""Value"":123}}", json);
}
}

public class MyPart : ContentPart
Expand All @@ -112,4 +129,9 @@ public class MyField : ContentField
{
public int Value { get; set; }
}

public class GetOnlyListPart : ContentPart
{
public IList<string> Texts { get; } = new List<string>();
}
}

0 comments on commit 7326e8c

Please sign in to comment.