You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The default HybridCache serializer uses JsonSerializer, but there is no way to configure the JsonSerializerOptions.
I think it is fairly common to have a custom JsonSerializerOptions which is helpful (or even necessary) for serializing cached types. Thus I think it would be helpful if it were easier to configure the JsonSerializerOptions used by the HybridCache.
As it stands now, you have to write your own serializer factory which is a lot of boilerplate.
API Proposal
In general I see 2 main options:
The DefaultJsonSerializerFactory tries to obtain a JsonSerializerOptions from the DI container (no API change)
The DefaultJsonSerializerFactory is made public, taking a JsonSerializerOptions parameter, so we can use it with .AddSerializerFactory(...) instead of re-implementing it
API Usage
For option 1, there's no change, you'd just need to add a singleton JsonSerializerOptions to DI
Option 1 could be considered a breaking change since the JSON serialization behaviour would change, however the hybrid cache is still experimental. Option 2 should not break anything.
The text was updated successfully, but these errors were encountered:
Background and motivation
The default HybridCache serializer uses
JsonSerializer
, but there is no way to configure theJsonSerializerOptions
.I think it is fairly common to have a custom
JsonSerializerOptions
which is helpful (or even necessary) for serializing cached types. Thus I think it would be helpful if it were easier to configure theJsonSerializerOptions
used by the HybridCache.As it stands now, you have to write your own serializer factory which is a lot of boilerplate.
API Proposal
In general I see 2 main options:
DefaultJsonSerializerFactory
tries to obtain aJsonSerializerOptions
from the DI container (no API change)DefaultJsonSerializerFactory
is made public, taking aJsonSerializerOptions
parameter, so we can use it with.AddSerializerFactory(...)
instead of re-implementing itAPI Usage
For option 1, there's no change, you'd just need to add a singleton
JsonSerializerOptions
to DIFor option 2, it would look something like this:
Alternative Designs
No response
Risks
Option 1 could be considered a breaking change since the JSON serialization behaviour would change, however the hybrid cache is still experimental. Option 2 should not break anything.
The text was updated successfully, but these errors were encountered: