dapr / dotnet-sdk

Dapr SDK for .NET
Apache License 2.0
1.12k stars 340 forks source link

Docs: Actor serialization documentation #1222

Closed WhitWaldo closed 10 months ago

WhitWaldo commented 11 months ago

Description

This is my first draft of a new page in the documentation detailing how serialization works using the Dapr .NET Actors SDK today. It's my response to the issue raised https://github.com/dapr/dotnet-sdk/issues/679 which is marked as a bug, but reflects a misunderstanding of how the serialization engine handles records. My goal with adding this page is to provide an upfront resource for developers using actors to understand why serialization may not be working as expected out of the box and provide not only a solution, but an explanation.

I detail how serialization is performed to illustrate the benefits to either going the parameterless constructor route or decorating types and members with the applicable attributes and then share my recommendation to use attributes and why. I dive through several examples documenting expectations in classes, structs and records and then speak a bit to other related scenarios (collections, enums, polymorphic types) towards the end pointing back to the official documentation to keep this document from getting too verbose.

This is a documentation update only and changes no code in the SDK.

This replaces a previous PR in which I had a commit that had an invalid DCO.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #679

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

~ [ ] Code compiles correctly~ ~ [ ] Created/updated tests~

codecov[bot] commented 11 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (233c620) 68.47% compared to head (76d2ce3) 68.47%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1222 +/- ## ======================================= Coverage 68.47% 68.47% ======================================= Files 172 172 Lines 5846 5846 Branches 648 648 ======================================= Hits 4003 4003 Misses 1681 1681 Partials 162 162 ``` | [Flag](https://app.codecov.io/gh/dapr/dotnet-sdk/pull/1222/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dapr) | Coverage Δ | | |---|---|---| | [net6](https://app.codecov.io/gh/dapr/dotnet-sdk/pull/1222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dapr) | `68.46% <ø> (ø)` | | | [net7](https://app.codecov.io/gh/dapr/dotnet-sdk/pull/1222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dapr) | `68.46% <ø> (ø)` | | | [net8](https://app.codecov.io/gh/dapr/dotnet-sdk/pull/1222/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dapr) | `68.46% <ø> (ø)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dapr#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

onionhammer commented 10 months ago

This doesn't mention JSON serialization, which IIRC is an option now?

WhitWaldo commented 10 months ago

@onionhammer That's right. This was intended largely to speak to the issue raised in #679 to explain why data contract serialization and records regarding actors didn't appear to work automagically (and to speak to why the new primary class constructors might yield a similar experience), but I didn't dig into the JSON serialization route at all.