DEV Community

Discussion on: [C #] Some scenarios for deserializing a JSON to a type with read-only properties by "System.Text.Json"

Collapse
 
arahaan profile image
AraHaan

I love how when I have something like this:

public record Person
{
    public string Name { get; init; }
    public int Age { get; init; }
    public string Address { get; init; }
    public string Pin { get; init; }
}
Enter fullscreen mode Exit fullscreen mode

However when I need to deserialize data from json with any value, for some reason it's always the default value.
oddly enough it never does that with CsWin32 and for some reason works when they do something like that though.

Collapse
 
arahaan profile image
AraHaan

Interesting it still fails when I add 2 dummy ctors to it as well.