Skip to content
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

feat: move to System.Text.Json as serialiser #249

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

sighphyre
Copy link
Member

@sighphyre sighphyre commented Oct 28, 2024

This removes the deprecated option to set your own JSON serializer. This should be very low impact on consumers, since this just requires them to remove a custom serializer if one had previously be set. The SDK now uses System.Text.Json which is built into most modern versions of .NET and is added as a dependency for legacy versions that don't support it natively.

Almost all of this PR is noise removing references, I'll mark relevant sections with some comments

Discussion

There's some, frankly, weird stuff around streams in the SDK at the moment. I'm 99% sure that's an artifact of the old, slightly awkward interfaces. I've chosen to throw that out, write directly and let the HTTP client deal with the buffering. I'm pretty sure that's not a big loss since the old implementation was flushing to the streams multiple times and the new implementation can use async to not have to worry too much about what's being blocked

using (var request = new HttpRequestMessage(HttpMethod.Post, requestUri))
{
request.Content = new StreamContent(memoryStream, bufferSize);
request.Content = new StringContent(JsonSerializer.Serialize(registration, options), Encoding.UTF8, "application/json");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swap out new streaming. This should have a default buffer of 1024 * 4 bytes anyway

@@ -71,6 +71,7 @@
</PackageReference>
<PackageReference Include="murmurhash" Version="1.0.3" />
<PackageReference Include="NuGet.Versioning" Version="6.1.0" />
<PackageReference Include="System.Text.Json" Version="8.0.5" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Force a reference to System.Text.Json for older versions that don't have it built in

@@ -8,7 +8,6 @@
using Unleash.Internal;
using Unleash.Events;
using Unleash.Communication;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be dead code. It got yeeted

@sighphyre
Copy link
Member Author

Closes #221

Copy link
Collaborator

@daveleek daveleek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! You have my blessing, feels good to get some of this complexity removed. A little paranoid testing as we've already discussed, for instance before and after this change with backups created by one and then loaded by the other might not be a bad idea.

@sighphyre sighphyre merged commit df6ac64 into main Oct 29, 2024
2 checks passed
@sighphyre sighphyre deleted the feat/use-built-in-serializer branch October 29, 2024 14:04
@sighphyre
Copy link
Member Author

@daveleek I'm less worried about loading features from file, that's effectively a cache miss on major upgrade which feels okay. Bit worried about Edge so agree we need to validate this more before release

We can play tomorrow and try break it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants