Appearance
Populate Method
Definition
- Namespace:
JASE.Serializers - Assembly:
JASE.Serializers.dll
Overloads
| Name | Description |
|---|---|
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
| Name | Description |
|---|---|
json | UTF-8 encoded JSON bytes whose root element must be an object. |
mode | Controls how object-valued properties are applied. See Populate. |
nullHandling | Controls how JSON null tokens are handled. See Populate. |
options | Optional JsonSerializerOptions. When , the library defaults are used. |
target | The 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
| Name | Description |
|---|---|
json | A JSON string whose root element must be an object. Only properties present in json are applied; properties absent from json are left unchanged. |
mode | Controls 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. |
nullHandling | Controls how JSON null tokens are handled for target properties. |
options | Optional JsonSerializerOptions. When , the library defaults are used. Naming policy and case-sensitivity are taken from these options. |
target | The 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
| Name | Description |
|---|---|
T | The target instance type. |
Parameters
| Name | Description |
|---|---|
json | A JSON string whose root element must be an object. Only properties present in json are applied; properties absent from json are left unchanged. |
mode | Controls how object-valued properties are applied. See Populate. |
nullHandling | Controls how JSON null tokens are handled. See Populate. |
options | Optional JsonSerializerOptions. When , the library defaults are used. |
target | The instance to be updated. |