Class SerializerOptions
serialization options for the endpoints
Inherited Members
Namespace: FastEndpoints
Assembly: FastEndpoints.dll
Syntax
public sealed class SerializerOptions
Properties
Options
the json serializer options
Declaration
public JsonSerializerOptions Options { get; }
Property Value
Type | Description |
---|---|
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:
HttpRequest : the incoming request
Type : the type of the request dto which the request body will be deserialized into
JsonSerializerContext? : json serializer context if code generation is used
CancellationToken : a cancellation token
Declaration
public Func<HttpRequest, Type, JsonSerializerContext?, CancellationToken, ValueTask<object?>> RequestDeserializer { set; }
Property Value
Type | Description |
---|---|
Func<HttpRequest, Type, JsonSerializerContext, CancellationToken, ValueTask<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:
HttpResponse : the http response object
object : the response dto to be serialized
string : the response content-type
JsonSerializerContext? : json serializer context if code generation is used
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 |
---|---|
Func<HttpResponse, object, string, JsonSerializerContext, CancellationToken, 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 |
---|---|
string |