Skip to content

System.Text.Json silent null on List<> when respecting CS8618 #97639

Discussion options

You must be logged in to vote

When respecting CS8618 aka not using a setter with a List<> property

I'm not sure I understand this, the presence of a setter shouldn't have an impact on whether CS8618 is emitted. In this case, the warning occurs because the value isn't being initialized by the default constructor, despite there not being a setter defined.

we noticed that deserializing a model with System.Text.Json silently keeps the property to null, despite existing values in the JSON response.

This is by design, the serializer will not consider for deserialization any properties that are missing a setter (because they are inherently not writable). One exception to this rule is JsonObjectCreationHandling.Populate w…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rusudorin
Comment options

Answer selected by rusudorin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
Converted from issue

This discussion was converted from issue #97635 on January 29, 2024 13:42.