I am using SignalR Service
output binding for Azure Function. When I add some arguments to the message, it is being serialized by the library Microsoft.Azure.WebJobs.Extensions.SignalRService
. It is possible to use either System.Text.Json
or Newtonsoft.Json
for serialization.
I cannot figure out how to do provide custom settings for serialization (I want enums to be converted to strings and not numbers) with either of serializations.
Is there any way of doing this?
I have also tried to serialize myself, but then the library would escape everything to ensure valid json which is not quite ideal either.
Use System.Text.Json library
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.Configure<SignalROptions>(o => o.JsonObjectSerializer = new JsonObjectSerializer(
new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
}));
}
}
Use Newtonsoft.Json library
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.Configure<SignalROptions>(o => o.JsonObjectSerializer = new NewtonsoftJsonObjectSerializer(
new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
}));
}
}
More info and documentation is available here: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/signalr/Microsoft.Azure.WebJobs.Extensions.SignalRService/samples/Sample02_CustomizingJsonSerialization.md