-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add System.Text.Json IGrainStorageSerializer #9505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
willg1983
wants to merge
23
commits into
dotnet:main
Choose a base branch
from
willg1983:WG/SystemTextJsonStorage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR aims to add support for System.Text.Json for Grain state persistence.
System.Text.Json is optimized for performance and low-allocation, leading to potential performance gains when reading and writing grain state in Orleans. This does require all grain state to be serializable with System.Text.Json, which may require some developer involvement as it is not as forgiving or flexible as Newtonsoft.
This PR adds System.Text.Json support for Orleans types commonly serialized in grain state using the same structure as Newtonsoft, therefore allowing migration to STJ without breaking compatibility with existing persisted grain state.
Support has been added for:
Each with unit tests to verify the instance serialized with Newtonsoft can be deserialized by the System.Text.Json converter, and the instance serialized with System.Text.Json can be deserialized by Newtonsoft.
This has meant maintaining backward compatibility even in cases where the existing Newtonsoft output was less than optimal.
A good example of this is StreamId, which Newtonsoft serializes as:
whereas we could write it in a much more friendly and idiomatic format as
"namespace/key"
The more idiomatic approach is used when serializing the type as the key in a dictionary, and the backward compatible approach used in all other cases.
Replacing Newtonsoft with System.Text.Json as the default grain storage serialization is hidden behind an experimental flag in this PR. To enable it call:
Using System.Text.Json on individual persistence providers by setting their Serializer property if they have one is also possible.
STJ provides support for out-of-order metadata properties such as $id and $ref required for if we wanted toe enable cyclic referencing whilst maintaining backward compatibility with Newtonsoft, but only in .NET 9.0+ packages, which are not referenced by Orleans 9.0 currently.
StreamId.TryFormat method output was changed as it was not readable by the corresponding StreamId.Parse() method - this appeared to be unintentional but may not have been.
IUtf8SpanFormatter was also implemented on StreamId in this PR.
Remaining work in this PR:
Must
Should
Could
Won't
Microsoft Reviewers: Open in CodeFlow