Json serialization settings in Orleans
Several Orleans systems/components use json serialization. Orleans sets up its own default json settings and some systems allow certain overrides of this default. Much of this seems to have been setup before the introduction of dependency injection, names services, or options, and has some shortcomings.
• Unclear why default settings are necessary. Do we need a default, or should each system just provide its own settings. • Not discoverable. How do users know we have default json settings. • No way to modify the default. Only per component overrides are provided. • Ease of use. To get the default settings one needs a type resolver and grain interface, both of which have internal implementations.
Suggest examination of whether a global default is necessary, and if necessary a refactor of how it is configured, used and overridden.
It would be immensely useful to be able to add to the Converters list of the various JsonSerializerSettings. Right now I see no way to specify how to serialize custom types for types in third party libraries.
Hey guys) I've started developing the new service and I've discovered that there is no configuration support for adding custom converters into Json serializer settings. As a workaround, I'm going to use the custom Orleans build with json configuration overriding support so I'd like to bring it to the community.
Do you have any thoughts on how it should be implemented, so I will create a PR for this feature?
The quick and dirty fix I think is to expose some sort of
Action<JsonSerializerSettings> ConfigureJson {get;set;} in AdoNetGrainStorageOptions class for AdoNet persistence and something similar to other parts which are using Json serialization.
What do you think?
I've given 'some' thought to this but not as much as is probably necessary, so please take all this with a large grain of salt..
I'd initially envisioned acquiring the JsonSerializerSettings by name using Orleans' named services façade. See AddSingletonNamedService and GetServiceByName. Providers that needed json settings would use GetServiceByName using their name. If none was found they could use GetService to get the default.
The default could be registered to resolve to a concrete class DefaultJsonSerializerSettings, which sets up the defaults Orleans needs. If users wanted to override the default they could register their own, and still resolve the DefaultJsonSerializerSettings to read the settings Orleans needs into their own custom default. Same with any of the named JsonSerializerSettings, each could resolve the DefaultJsonSerializerSettings and copy any settings that weren't overridden.
All of the providers that now include json settings in their configuration options would have those settings removed, and simply read the named JsonSerializerSettings vi GetServiceByName. Helper functions could be added to set this up for users given commonly overridden fields, or an action, much like we do with configuration options.
Thoughts?
This seems like a reasonable candidate for named options. What do you think, @jason-bragg?
I've given 'some' thought to this but not as much as is probably necessary, so please take all this with a large grain of salt..
Public Class LargeGrain(Of Salt)
Public Async Function Take() As Task(Of Salt)
End Function
End Class
Anyone know if json serialization settings for adonet provider are exposed yet ?
@aktxyz seems like it: https://github.com/dotnet/orleans/blob/5b1d9cdf41f00cecd0f914667f1ca1a809c50e30/src/AdoNet/Orleans.Persistence.AdoNet/Options/AdoNetGrainStorageOptions.cs#L42-L57
Bingo ... thanks !
On Fri, Feb 28, 2020 at 11:06 PM Alex Rønne Petersen < [email protected]> wrote:
@aktxyz https://github.com/aktxyz seems like it: https://github.com/dotnet/orleans/blob/5b1d9cdf41f00cecd0f914667f1ca1a809c50e30/src/AdoNet/Orleans.Persistence.AdoNet/Options/AdoNetGrainStorageOptions.cs#L42
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dotnet/orleans/issues/4555?email_source=notifications&email_token=ACZTNI7W2PL3WZNJ2K5IS3TRFCLVBA5CNFSM4E6NEKN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOENLJSQI#issuecomment-592877889, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACZTNI2H5E7BGZFNUKE3KQ3RFCLVBANCNFSM4E6NEKNQ .
--
-- thanks, Andrew 512-484-1330 [email protected]