I am using .NET's System.Text.Json to deserialize json into an immutable class. I want to hide the constructor from the class user to prevent creating instances of this class and only create instances when deserializing. How can I make System.Text.Json use private constructor which is not default?
I want to do something like this:
public class Sheet
{
public string Id { get; }
public IEnumerable<IEnumerable<SheetCell>> Data { get; }
[JsonConstructor]
private Sheet(string id, IEnumerable<IEnumerable<SheetCell>> data)
{
Id = id;
Data = data;
}
}