Skip to content
Discussion options

You must be logged in to vote

For those interested, I got it figured out.

The Issue:

I am using the SystemTextJsonSerializer and System.Text.Json doesn't include public properties with private setters when deserializing.

Possible Solutions:

  1. Decorate all public properties with private setters with [JsonInclude] per the docs
  2. Create a Custom Contract using a Modifier per the docs
  3. Use init-only properties

My Solution:

I didn't want to decorate all of my properties or even all of my classes with an attribute. I also didn't want to use init-only properties because "anyone" can just new-up a class and set the properties to whatever they want. Besides, EF Core can handle private setters, why can't this?!

So I created a modi…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by mwasson74
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants