RegionOrebroLan / .NET-Localization-Extensions

Localization additions and extensions for .NET.
MIT License
0 stars 0 forks source link

Reminder: Why we keep Newtonsoft.Json #2

Open HansKindberg opened 2 years ago

HansKindberg commented 2 years ago

This is a reminder of one reason why we keep Newtonsoft.Json and do not move over to System.Text.Json.

Deserializing collections without setters work with Newtonsoft.Json but not out of the box with System.Text.Json. With System.Text.Json, custom converters are needed.

https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to#add-to-collections-without-setters

Eg:

To get it to work with System.Text.Json without custom converters we need:

Using the latter with analyzers enabled you need to suppress:

[SuppressMessage("Usage", "CA2227:Collection properties should be read only")] public virtual IList<SomeObject> Objects { get; set; } = new List<SomeObject>();