JsonSerializerOptions.PreferredObjectCreationHandling Property

Definition

Gets or sets the preferred object creation handling for properties when deserializing JSON.

C#
public System.Text.Json.Serialization.JsonObjectCreationHandling PreferredObjectCreationHandling { get; set; }

Property Value

When set to Populate, all properties that are capable of reusing the existing instance will be populated.

Remarks

Only property type is taken into consideration. For example, if a property is of type IEnumerable<T> but it is assigned List<T>, it won't be populated because IEnumerable<T> is not capable of populating. Additionally, value types require a setter to be populated.

Applies to

Product Versions
.NET 8 (package-provided), 8, 9 (package-provided), 9, 10 (package-provided), 10
.NET Standard 2.0 (package-provided)