JsonSerializationBinder Class
Abblix.Oidc.Server
Abblix.Oidc.Server.Common.Implementation
JsonSerializationBinder Class
Implements the IJsonObjectBinder interface to bind JSON data from a System.Text.Json.Nodes.JsonObject to a specified model type. This binder utilizes System.Text.Json for serialization to dynamically bind the JSON data to the model's properties, allowing for both creation of new model instances or updating existing ones based on the provided JSON data.
public class JsonSerializationBinder : Abblix.Oidc.Server.Common.Interfaces.IJsonObjectBinder
Inheritance System.Object → JsonSerializationBinder
Implements IJsonObjectBinder
Methods
JsonSerializationBinder.BindModelAsync<TModel>(JsonObject, TModel) Method
Asynchronously binds JSON data from a System.Text.Json.Nodes.JsonObject to a specified model of type TModel. The method can update an existing model instance with the data or create and populate a new instance if none is provided.
public System.Threading.Tasks.Task<TModel?> BindModelAsync<TModel>(System.Text.Json.Nodes.JsonObject properties, TModel? model=null)
where TModel : class;
Type parameters
TModel
The type of the model to which the data is to be bound.
Parameters
properties System.Text.Json.Nodes.JsonObject
The JSON data as a System.Text.Json.Nodes.JsonObject containing the properties to bind to the model.
model TModel
An optional instance of the model to be updated. If null, a new instance of TModel is created.
Implements BindModelAsync<TModel>(JsonObject, TModel)
Returns
System.Threading.Tasks.Task<TModel>
A System.Threading.Tasks.Task that, when completed, results in the bound model instance
of TModel, or null if the binding fails.
Remarks
This method leverages the JSON serialization capabilities of System.Text.Json to map the JSON properties to the corresponding properties of the model. It's designed to handle complex object graphs and can be used to easily populate models from JSON data or update existing models with new data.