I want to add the StringEnumConverter
to my serializer settings for SignalR but I can't seem to find a way how to do this.
Right now i added the attribute on my transfer object that does the trick but it would be much nicer to define this globally like you can with Mvc
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.Converters.Add(new StringEnumConverter(true));
});
But then for SignalR.
This can be achieved by chaining a call to AddJsonProtocol
on to AddSignalR
in ConfigureServices
. Here's an example:
services.AddSignalR()
.AddJsonProtocol(options =>
{
options.PayloadSerializerSettings.Converters.Add(new StringEnumConverter(true));
});
Reference: JSON/MessagePack serialization options