Skip to content

Allowing private fields initialization in constructor with System.Text.Json #55036

Locked Answered by terrajobst
mickturn asked this question in Ideas
Discussion options

You must be logged in to vote

@mickturn

Quoting your document here, for easier reading:

Private fields deserialization

Json objects look like this:

{ "id" : 1, "name" : "test" }

Here, the private fields are being populated in the constructor allowing complete object deserialization.

But it works only when we add accessors that are not themselves serialized... Without them you get:

'Each parameter in constructor 'Void .ctor(UInt16, System.String)' on type 'Experiments.Test' must bind to an object property or field on deserialization. Each parameter name must match with a property or field on the object. The match can be case-insensitive.'

Why not allowing private fields initialization in constructor without the need…

Replies: 3 comments

This comment was marked as disruptive content.

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by terrajobst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
4 participants