C# – Deserialize JSON with a specific constructor
When your class has multiple constructors, you can use the JsonConstructor attribute to specify which constructor to use during deserialization. Here’s an example. The Person class has two constructors. I put the JsonConstructor attribute on one of the constructors: Note: JsonConstructor for System.Text.Json was added in .NET 5. Now deserialize a JSON string to the … Read more