Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR 2.0.0 beta2 IJsonSerializer extensibility

I want to add some custom serialization logic so that the converted json contains camel case properties.

For that reason i tried to replace the default IJsonSerializer with one the i found in this link:

https://github.com/SignalR/SignalR/issues/500

However there seems to be a problem. More specifically, the JsonNetSerializer and IJsonSerializer classes do not exist in any of the signalR assemblies. Is there any change that happened to the recent version of signalR in that respect?

like image 279
ppoliani Avatar asked Aug 06 '13 10:08

ppoliani


Video Answer


1 Answers

Just to clarify this a bit, as of SignalR 2 you can't replace the serializer with one that isn't from from JSON.NET. However, the JSON.NET serializer used by SinglR can be created and set using the DependacyResolver.

Here's an example where a new JsonSerializer is created to handle reference loops:

  protected void Application_Start()
  {
     var serializerSettings = new JsonSerializerSettings();
     serializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
     serializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;

     var serializer = JsonSerializer.Create(serializerSettings);
     GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), () => serializer); 
  }
like image 148
mbursill Avatar answered Oct 20 '22 00:10

mbursill