Using .NET Core RC2. Got SignalR working, but trying to get it returning camelCase properties in JSON.
For APIs I'm using...
services.AddMvc().AddJsonOptions(o => {
o.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
Maybe there's just nothing in place yet for SignalR (after all, it's not even supposed to work yet...), but wondering if anyone's figured it out yet? I've tried a few things like...
services.AddTransient<IContractResolver, CamelCasePropertyNamesContractResolver>();
... but no go.
Anyone got this working yet?
In SignalR 3.0 you can do this with the following statement, as described in the Microsoft Docs
services.AddSignalR()
.AddNewtonsoftJsonProtocol(
options =>
options.PayloadSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver()
);
In .NET Core 3.0, using System.Text.Json
services.AddSignalR().AddJsonProtocol(options =>
{
options.PayloadSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With