DEV Community

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

Collapse
 
j_sakamoto profile image
jsakamoto

I want to be to respect other's opinions, and also I partially agree with what you said, but you are too much afraid of it, I feel.

Pretty much cases, "constructor initialized read-only properties" immutable object pattern - and this is a very standard and classical pattern in C#, I think - works fine with "System.Text.Json" without additional coding.

And, the "no constructor and init-only properties" immutable object pattern - this is a modern pattern - will also work fine with "System.Text.Json" too. Of course, it doesn't require additional coding.

In this article, I just explained rare cases for someone who runs into the JSON deserialization problem, such as the class has multiple constructors.

I agree that there are too many ways to do something in recent C# programming, but recent C# programmers will use modern patterns, so the use cases of the classical ways will decrease.

For example, the "anonymous delegate" feature is still alive in the newest C#, but we usually use "lambda expression" instead of it today, so recent C# programmers may not know "anonymous delegate".

So, in my opinion, I'm optimistic about this C# programming topic. 😊