You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now if your content elements contain any get-only collections, those don't get populated by System.Text.Json. they are just left empty. This is an unintended breaking change compared to Newtonsoft.
Note: I'm not entirely sure what the second one means, but it's necessary otherwise the site crashes with the message "System.InvalidOperationException: JsonObjectCreationHandling.Populate is incompatible with reference handling." (see). I suspect it's about handling circular references, but I'm not sure. If anyone has some insight, please chime in.
Screenshots
A minimal sample (not using OC) to show the problem (the "B.Items") and solution (the "B.Items (with options)").
Yes. As a workaround, add init; to the property and it will get populated. This is also documented in the 1.9 release. Your fix is good, but not sure if it has impact to other options.
Describe the bug
Right now if your content elements contain any get-only collections, those don't get populated by System.Text.Json. they are just left empty. This is an unintended breaking change compared to Newtonsoft.
Why have get-only collection props in the first place? See the explanation in the static code analysis warning CA2227: Collection properties should be read only.
To Reproduce
Expected behavior
In Newtonsoft get-only collections (lists, dictionaries, etc) are automatically populated (see mode on the comparison here).
Solution
JOptions.Base
should contain the configurations:PreferredObjectCreationHandling = JsonObjectCreationHandling.Populate
ReferenceHandler = null
Note: I'm not entirely sure what the second one means, but it's necessary otherwise the site crashes with the message "System.InvalidOperationException: JsonObjectCreationHandling.Populate is incompatible with reference handling." (see). I suspect it's about handling circular references, but I'm not sure. If anyone has some insight, please chime in.
Screenshots
A minimal sample (not using OC) to show the problem (the "B.Items") and solution (the "B.Items (with options)").
A real life example in Lombiq Content Editors for Orchard Core.
The text was updated successfully, but these errors were encountered: