Class SerializerOptions
serialization options for the endpoints
Inheritance
Inherited Members
Namespace: FastEndpoints
Assembly: FastEndpoints.dll
Syntax
public class SerializerOptions
Properties
Options
the json serializer options
Declaration
public JsonSerializerOptions Options { get; }
Property Value
Type | Description |
---|---|
System.Text.Json.JsonSerializerOptions |
RequestDeserializer
a function for deserializing the incoming http request body. this function will be executed for each request received if it has a json request body. the input parameters of the func are as follows:
Microsoft.AspNetCore.Http.HttpRequest : the incoming request
System.Type : the type of the request dto which the request body will be deserialized into
System.Text.Json.Serialization.JsonSerializerContext? : json serializer context if code generation is used
System.Threading.CancellationToken : a cancellation token
Declaration
public Func<HttpRequest, Type, JsonSerializerContext, CancellationToken, ValueTask<object>> RequestDeserializer { set; }
Property Value
Type | Description |
---|---|
System.Func<Microsoft.AspNetCore.Http.HttpRequest, System.Type, System.Text.Json.Serialization.JsonSerializerContext, System.Threading.CancellationToken, System.Threading.Tasks.ValueTask<System.Object>> |
ResponseSerializer
a function for writing serialized response dtos to the response body. this function will be executed whenever a json response is being sent to the client. you should set the content-type and write directly to the http response body stream in this function. the parameters of the func are as follows:
Microsoft.AspNetCore.Http.HttpResponse : the http response object
System.Object : the response dto to be serialized
System.String : the response content-type
System.Text.Json.Serialization.JsonSerializerContext? : json serializer context if code generation is used
System.Threading.CancellationToken : a cancellation token
example:
config.ResponseSerializer = (rsp, dto, cType, jCtx , ct) =>
{
rsp.ContentType = cType;
return rsp.WriteAsync(Newtonsoft.Json.JsonConvert.SerializeObject(dto), ct);
};
Declaration
public Func<HttpResponse, object, string, JsonSerializerContext, CancellationToken, Task> ResponseSerializer { set; }
Property Value
Type | Description |
---|---|
System.Func<Microsoft.AspNetCore.Http.HttpResponse, System.Object, System.String, System.Text.Json.Serialization.JsonSerializerContext, System.Threading.CancellationToken, System.Threading.Tasks.Task> |
SerializerErrorsField
this is the field name used for adding serializer errors when the serializer throws due to bad json input and the error is not concerning a particular property/field of the incoming json.
Declaration
public string SerializerErrorsField { set; }
Property Value
Type | Description |
---|---|
System.String |