Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update JOptions configuration (Lombiq Technologies: OCORE-149) #15534

Merged
merged 6 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>();
}
}
Loading