Unleash / unleash-client-dotnet

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

Avoid subtle errors and improve DX when setting a custom serializer #222

Open karimkod opened 1 month ago

karimkod commented 1 month ago

Is your feature request related to a problem? Please describe. Recently we switched to using System.Text.Json and we fell in the same error as #197 and it went unoticed until production because no one knew that we had to set stream.Position = 0 in the serializer. We might have it in the unleash doc, but I think even that won't fix the real root cause.

Describe the solution you'd like I think it would be better to set the stream.Position inside the method that is calling the serializer (when needed), this way we won't have the developer to set it at the end of the Serialize method of the serializer.

Proposed implementation add stream.Position = 0 here : https://github.com/Unleash/unleash-client-dotnet/blob/93f4d88a1058581960752d754954dee665a16435/src/Unleash/Communication/UnleashApiClient.cs#L237

Again, if this is a good way to do it and I'm not missing context, I will be very happy to submit a PR.

Thanks 😊

daveleek commented 1 month ago

Hello @karimkod and thank you for raising this! We'll have a look and get back to you!