C# System.Text.Json.Deserialize<GProject>() wont use [JsonConstructor]

I have a class like this.

    public class GProject : Project
    {
        public GProject()
        {

        }

        [JsonConstructor]
        public GProject(ISaveRow value, List<ISaveList> lists, List<ISaveGroup> groups)
        {

        }
    }

When I use System.Text.Json.Deserialize(MyJson) I want to use specific constructor with attribute [JsonConstructor]. From my google search,[JsonConstructor] should allways be called when I use System.Text.Json.Deserialize, but its not and the very first constructor to be used is still GProject() {} - I doesnt want that.

https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-immutability?pivots=dotnet-5-0
...For a struct, or a class with multiple constructors, specify the one to use by applying the [JsonConstructor] attribute. ...

Can you give me some tips on how to resolve this problem?



Read more here: https://stackoverflow.com/questions/68484796/c-sharp-system-text-json-deserializegproject-wont-use-jsonconstructor

Content Attribution

This content was originally published by Jaroslav Súkeník at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: