Custom serialization of HubResponse.Result and ClientHubInvocation.Args #957

KrzysFR opened this Issue Nov 13, 2012 · 0 comments


None yet
2 participants

KrzysFR commented Nov 13, 2012

After discussing again the subject of custom serialization on JabbR, I'm opening this new Issue to keep track of the scenario I'm trying to accomplish.

I want to custom serialize objects that are returned by hub methods, and arguments to client hub invocations. I only care about these types, and I'm perfectly fine with have JSON.Net doing whatever it wants with the other internal objects in SignalR's namespace.

Specifically, I need a way to be able to able to serialize ANY type that would be in the following properties:

  • Microsoft.AspNet.SignalR.Message.Value: string that is the already serialized version of a message sent/broadcasted to clients.
  • Microsoft.AspNet.SignalR.Hubs.HubResponse.Result: object that contains the return value of a hub method
  • Microsoft.AspNet.SignalR.Hubs.ClientHubInvocation.Args: object array that contains the arguments of the method to call on the clients

The first is already possible if I provide a custom IJsonSerializer to the global Dependency Resolver, and works pretty well. The string gets appended as Raw JSON when SR serializes the PersistentResponse.

The other two are difficult to achieve if you are not using JSON.Net for custom serialization. the IJsonSerializer.Serialize(object, TextWriter) is called with, for example, the HubResponse object, and the Value is in a child property. Same thing for ClientHubInvocation

I can't whitelist the types that I need custom serialized, because the majority of them are Anonymous Types, or dynamic (ExpandoObject, or others).

The only known filter is that they are stored inside the "Result" member of HubResponse, and inside the Args member of ClientHubInvocation.

Also, I need to have access to the output TextWriter in order to write my own JSON text.

So basically, some Action<object, TextWriter> I could give to SR, and have it called only for this members.

How can I do that ?

@davidfowl davidfowl closed this Jan 19, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment