Skip to content

Populate Method ​

Definition ​

  • Namespace: JASE.Serializers
  • Assembly: JASE.Serializers.dll

Overloads ​

NameDescription
void Populate(object target, byte[] json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null)Populates an existing object instance with values from a UTF-8 encoded JSON object payload.
void Populate(object target, string json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null)Populates an existing object instance with values from a JSON object payload.
void Populate(T target, string json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null)Populates an existing instance of T with values from a JSON object payload.

void Populate(object target, byte[] json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null) ​

csharp
void Populate(object target, byte[] json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null)

Populates an existing object instance with values from a UTF-8 encoded JSON object payload.

Parameters ​

NameDescription
jsonUTF-8 encoded JSON bytes whose root element must be an object.
modeControls how object-valued properties are applied. See Populate.
nullHandlingControls how JSON null tokens are handled. See Populate.
optionsOptional JsonSerializerOptions. When , the library defaults are used.
targetThe object instance to be updated.

Remarks ​

This overload converts the UTF-8 bytes to a string and then delegates to Populate.

void Populate(object target, string json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null) ​

csharp
void Populate(object target, string json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null)

Populates an existing object instance with values from a JSON object payload.

Parameters ​

NameDescription
jsonA JSON string whose root element must be an object. Only properties present in json are applied; properties absent from json are left unchanged.
modeControls how object-valued properties are applied: Replace: object-valued properties are deserialized and assigned (replacing the existing value).PopulateNested: if the JSON value is an object and the target property already contains a non-null reference, this method recursively populates the existing instance; otherwise the value is deserialized and assigned.
nullHandlingControls how JSON null tokens are handled for target properties.
optionsOptional JsonSerializerOptions. When , the library defaults are used. Naming policy and case-sensitivity are taken from these options.
targetThe object instance to be updated. Only writable public properties are considered.

Remarks ​

Unknown JSON properties are ignored.

This method sets values via reflection. Property setters must be publicly writable for assignment to succeed.

Arrays are deserialized and assigned as a whole. No element-level merge behavior is performed.

void Populate(T target, string json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null) ​

csharp
void Populate(T target, string json, JsonSerializerOptions options = null, JsonObjectPopulateMode mode = null, JsonNullHandling nullHandling = null)

Populates an existing instance of T with values from a JSON object payload.

Type parameters ​

NameDescription
TThe target instance type.

Parameters ​

NameDescription
jsonA JSON string whose root element must be an object. Only properties present in json are applied; properties absent from json are left unchanged.
modeControls how object-valued properties are applied. See Populate.
nullHandlingControls how JSON null tokens are handled. See Populate.
optionsOptional JsonSerializerOptions. When , the library defaults are used.
targetThe instance to be updated.