Skip to content

Added .NET SDK examples to serialization document #4596

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

Open
wants to merge 7 commits into
base: v1.15
Choose a base branch
from

Conversation

WhitWaldo
Copy link
Contributor

Thank you for helping make the Dapr documentation better!

Please follow this checklist before submitting:

  • Commits are signed with Developer Certificate of Origin (DCO - learn more)
  • Read the contribution guide
  • Commands include options for Linux, MacOS, and Windows within codetabs
  • New file and folder names are globally unique
  • Page references use shortcodes instead of markdown or URL links
  • Images use HTML style and have alternative text
  • Places where multiple code/command options are given have codetabs

In addition, please fill out the following to help reviewers understand this pull request:

Description

The SDK serialization page claimed that only Java uses JSON serialization. To my knowledge, that's not accurate at all - all of the languages use JSON, though there have been recent requests for other serialization approaches. Regardless... while supposedly addressing serialization requirements across the solution, it only provided Java-specific examples. This PR adds .NET examples that are current (for now) to the 1.16 release.

Issue reference

Please reference the issue this PR will close: #4595

@WhitWaldo WhitWaldo self-assigned this Mar 22, 2025
@WhitWaldo WhitWaldo requested review from a team as code owners March 22, 2025 23:59
Copy link

Stale PR, paging all reviewers

@github-actions github-actions bot added the stale label Mar 28, 2025
@WhitWaldo WhitWaldo removed the stale label Mar 28, 2025
Copy link

github-actions bot commented Apr 3, 2025

Stale PR, paging all reviewers

@github-actions github-actions bot added the stale label Apr 3, 2025
@WhitWaldo WhitWaldo removed the stale label Apr 3, 2025
Copy link

github-actions bot commented Apr 9, 2025

Stale PR, paging all reviewers

@github-actions github-actions bot added the stale label Apr 9, 2025
@WhitWaldo WhitWaldo removed the stale label Apr 9, 2025
@WhitWaldo
Copy link
Contributor Author

@alicejgibbons Any chance you could review this?

Updated formatting and grammar

Signed-off-by: Mark Fussell <[email protected]>
Copy link
Member

@msfussell msfussell left a comment

Choose a reason for hiding this comment

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

LGTM but will also let @alicejgibbons comment

Copy link
Contributor

@alicejgibbons alicejgibbons left a comment

Choose a reason for hiding this comment

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

Thanks Whit, big improvement but just a couple small things.

@@ -8,16 +8,40 @@ aliases:
- '/developing-applications/sdks/serialization/'
---

An SDK for Dapr should provide serialization for two use cases. First, for API objects sent through request and response payloads. Second, for objects to be persisted. For both these use cases, a default serialization is provided. In the Java SDK, it is the [DefaultObjectSerializer](https://dapr.github.io/java-sdk/io/dapr/serializer/DefaultObjectSerializer.html) class, providing JSON serialization.
An SDK for Dapr should provide serialization for two use cases. First, for API objects sent through request and response payloads. Second, for objects to be persisted. For both these use cases, a default serialization is provided.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
An SDK for Dapr should provide serialization for two use cases. First, for API objects sent through request and response payloads. Second, for objects to be persisted. For both these use cases, a default serialization is provided.
Dapr SDKs provide serialization for two use cases. First, for API objects sent through request and response payloads. Second, for objects to be persisted. For both of these cases, a default serialization method is provided in each language SDK.


| Language SDK | Default Serializer |
|------------------------------|------------------------------------------------------------------------------------------------------------|
| [.NET]({{< ref dotnet >}}) | DataContracts for remoted actors, System.Text.Json otherwise | |
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| [.NET]({{< ref dotnet >}}) | DataContracts for remoted actors, System.Text.Json otherwise | |
| [.NET]({{< ref dotnet >}}) | [System.Text.Json](https://www.nuget.org/packages/system.text.json/) and [DataContracts ](https://www.nuget.org/packages/LogicBuilder.DataContracts) for remoted actors, | |

Copy link
Contributor

Choose a reason for hiding this comment

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

@WhitWaldo would it make sense to link the remoted actors text to this page? https://docs.dapr.io/developing-applications/sdks/dotnet/dotnet-actors/dotnet-actors-serialization/#strongly-typed-dapr-actor-client

Also lmk if i linked the wrong nuget to data contracts

|------------------------------|------------------------------------------------------------------------------------------------------------|
| [.NET]({{< ref dotnet >}}) | DataContracts for remoted actors, System.Text.Json otherwise | |
| [Java]({{< ref java >}}) | [DefaultObjectSerializer](https://dapr.github.io/java-sdk/io/dapr/serializer/DefaultObjectSerializer.html) for JSON serialization|
| [JavaScript]({{< ref js >}}) | JSON |
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| [JavaScript]({{< ref js >}}) | JSON |
| [JavaScript]({{< ref js >}}) | [JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON) |

In the example above, the app will receive a `POST` request for the `saySomething` method with the request payload as `"My Message"` - quoted since the serializer will serialize the input String to JSON.
{{% /codetab %}}

In the example above, the app receives a `POST` request for the `saySomething` method with the request payload as
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
In the example above, the app receives a `POST` request for the `saySomething` method with the request payload as
In the example above, the app `myappid` receives a `POST` request for the `saySomething` method with the request payload as


<!-- Java -->
{{% codetab %}}

```java
DaprClient client = (new DaprClientBuilder()).build();
client.invokeService("myappid", "saySomething", "My Message", HttpExtension.POST).block();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
client.invokeService("myappid", "saySomething", "My Message", HttpExtension.POST).block();
client.invokeMethod("myappid", "saySomething", "My Message", HttpExtension.POST).block();

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the newer java examples we are using invokeMethod not invokeService.

Copy link
Contributor

Choose a reason for hiding this comment

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

@cicoyle can you confirm that this is the correct example we should be giving in the docs.

```csharp
using var client = (new DaprClientBuilder()).Build();
await client.InvokeBindingAsync("sample", "My Message");
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Input binding example? @WhitWaldo

It should print:
```
My Message
```

## Actor Method invocation
Object serialization and deserialization for invocation of Actor's methods are same as for the service method invocation, the only difference is that the application does not need to deserialize the request or serialize the response since it is all done transparently by the SDK.
Object serialization and deserialization for invocation of Actor's methods are same as for the service method invocation,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Object serialization and deserialization for invocation of Actor's methods are same as for the service method invocation,
Object serialization and deserialization for Actor method invocation are same as for the service method invocation,

the only difference is that the application does not need to deserialize the request or serialize the response since it
is all done transparently by the SDK.

For an Actor's methods, the SDK only supports methods with zero or one parameter.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
For an Actor's methods, the SDK only supports methods with zero or one parameter.
For Actor methods, the SDK only supports methods with zero or one parameter.


{{< tabs ".NET" "Java" >}}

The .NET SDK supports two different serialization types based on whether you're using the strongly-typed (DataContracts)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The .NET SDK supports two different serialization types based on whether you're using the strongly-typed (DataContracts)
The .NET SDK supports two different serialization types based on whether you're using strongly-typed (DataContracts)

{{% /codetab %}}

<!-- Java -->
{{% codetab %}}
Copy link
Contributor

Choose a reason for hiding this comment

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

I also don't think that this invokeActorMethod is correct anymore (unless you're using springboot?). @cicoyle can you take a peek at this actors example?

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

Successfully merging this pull request may close these issues.

SDK serialization should be more generic
3 participants