Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Support specifying custom JSON.NET options for JsonHubProtocol #261

Closed
evenflow58 opened this issue Mar 2, 2017 · 10 comments
Closed

Support specifying custom JSON.NET options for JsonHubProtocol #261

evenflow58 opened this issue Mar 2, 2017 · 10 comments

Comments

@evenflow58
Copy link

I would like to add a contract resolver to signalR requests in order to camel case my return types. I tried used the pattern described here but the contract resolver seems to be ignored. Has this been implemented? Here's a repository with my attempt. I would expect the returned value from GetMessage to be { message: 'a message' } but I get { Message: 'a message' }.

@moozzyk
Copy link
Contributor

moozzyk commented Mar 3, 2017

No, customizing serialization is not possible at the moment. This case is quite interesting however - you want to modify the payload on the server to get camelCased property names because you are using only a javascript client. If you used heterogeneous clients (e.g. javascript and C#) then modifying the payload on the server side wouldn't work since the clients use different conventions.

@muratg
Copy link

muratg commented Mar 17, 2017

cc @DamianEdwards

@muratg muratg added this to the 1.0.0-preview1 milestone Mar 31, 2017
@analogrelay analogrelay removed their assignment Jun 7, 2017
@muratg
Copy link

muratg commented Jun 16, 2017

@davidfowl do you have a design in mind?

@muratg muratg modified the milestones: 2.1.0, 2.1.0-preview1 Jun 16, 2017
@davidfowl davidfowl modified the milestones: 2.1.0-preview1, 2.1.0 Jun 28, 2017
@davidfowl
Copy link
Member

davidfowl commented Jun 28, 2017

This should be in preview. We need a way to configure these options and have them flow to the JsonHubProtocol implementation.

@moozzyk
Copy link
Contributor

moozzyk commented Jun 28, 2017

We could try resolving JsonSerializerSettings from DI in the JSonHubProtocol ctor.

Note that if we decide to support this we will need two JSonSerializers - one for the hub protocol itself that is not configurable and one for serializing custom types.

@davidfowl davidfowl changed the title Are contract resolver implemented? Support specifying custom JSON.NET options for default formatter Jun 28, 2017
@muratg muratg mentioned this issue Jun 28, 2017
55 tasks
@davidfowl davidfowl mentioned this issue Jun 28, 2017
@davidfowl davidfowl changed the title Support specifying custom JSON.NET options for default formatter Support specifying custom JSON.NET options for JsonHubProtocol Jun 28, 2017
@moozzyk
Copy link
Contributor

moozzyk commented Jun 28, 2017

another option (if registering in DI feels to general) is to have it in HubOptions where it could possibly be specified per HubProtocol implementation.

@analogrelay
Copy link
Contributor

That actually feels like the best option to me. Have a way to specify Hub Protocol options (of various kinds, including which protocols to allow)

@ssougnez
Copy link

ssougnez commented Aug 7, 2017

Hi, maybe what I'm about to propose is the same as you (because I didn't really understood it :-$) but why can't you just do something like:

services.AddSignalR(options => options.JsonContractResolver = new CamelCasePropertyNamesContractResolver());

And this would only applied to what's send in the "arguments" property of the response? This way, the user would be able to choose if he wants to keep the default behaviour (for C# client for example) or switch to Camel case (for JavaScript client).

@analogrelay
Copy link
Contributor

@ssougnez Yep, that's basically exactly what we're talking about. It'll likely be a JsonSerializerSettings you'll be able to provide, which gives you Contract Resolver access, but also a bunch of other settings.

This was referenced Aug 18, 2017
@BrennanConroy
Copy link
Member

This is now in via #743

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants