Unleash / unleash-client-dotnet

Unleash client SDK for .NET
Apache License 2.0
77 stars 39 forks source link

Built-in JSON serialization without reflection #221

Open gastonfournier opened 1 month ago

gastonfournier commented 1 month ago

Is your feature request related to a problem? Please describe. Depending on a Json serialization library that requires a custom implementation, can lead to errors. In particular, when defining a custom serialization with system.text if we forget to do stream.Position = 0; the payload will not be serialized properly, leading to errors downstream.

Describe the solution you'd like Serialization should be provided by the SDK, it's not something users should override, as there's only 1 correct way of serializing the payload. The downside is that the actual users, that are using a custom serializer might cause a crash at runtime.

Describe alternatives you've considered None, but open to suggestions

Additional context As a sample test, I wrote a test for System.text as serializer. It's currently not working because the test compares strings to strings and the only difference is the sort order of fields. So it's the test that needs to change. On top of that, the test is not covering serialization of metrics, so it's incomplete. But it's a good enough to prove the point that serialization is dangerous if left in the hands of users and it should be handled by the SDK without giving users the ability to override it:

https://github.com/Unleash/unleash-client-dotnet/compare/system-text-serialization-test?expand=1

gastonfournier commented 1 month ago

We're making this issue visible after some issues caused by custom serializers, but it's not gonna be prioritized soon. We'd like to collect some feedback from the community (you), and why not some contribution.

stale[bot] commented 3 weeks ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.