From 96a1e27221b546075185de8fa8493cce2cb0675e Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Sat, 22 Mar 2025 18:52:53 -0500 Subject: [PATCH 01/14] Added .NET SDK examples to serialization document + modernized it some Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 194 ++++++++++++++++-- 1 file changed, 181 insertions(+), 13 deletions(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 4e22d8b58cb..0652f7c65f3 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -8,16 +8,42 @@ 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. +In the Java SDK, it is the [DefaultObjectSerializer](https://dapr.github.io/java-sdk/io/dapr/serializer/DefaultObjectSerializer.html) class, providing JSON serialization. + +| Language | Default Serializer | +|------------------------------|------------------------------------------------------------------------------------------------------------| +| [.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) | +| [JavaScript]({{< ref js >}}) | JSON | ## Service invocation +{{< tabs ".NET" "Java" >}} + + +{{% codetab %}} + +```csharp + using var client = (new DaprClientBuilder()).Build(); + await client.InvokeMethodAsync("myappid", "saySomething", "My Message"); +``` + +{{% /codetab %}} + + +{{% codetab %}} + ```java DaprClient client = (new DaprClientBuilder()).build(); client.invokeService("myappid", "saySomething", "My Message", HttpExtension.POST).block(); ``` -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 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. ```text POST /saySomething HTTP/1.1 @@ -30,11 +56,35 @@ Content-Length: 12 ## State management +{{< tabs ".NET" "Java" >}} + + +{{% codetab %}} + +```csharp + using var client = (new DaprClientBuilder()).Build(); + var state = new Dictionary + { + { "key": "MyKey" }, + { "value": "My Message" } + }; + await client.SaveStateAsync("MyStateStore", "MyKey", state); +``` + +{{% /codetab %}} + + +{{% codetab %}} + ```java DaprClient client = (new DaprClientBuilder()).build(); client.saveState("MyStateStore", "MyKey", "My Message").block(); ``` -In this example, `My Message` will be saved. It is not quoted because Dapr's API will internally parse the JSON request object before saving it. + +{{% /codetab %}} + +In this example, `My Message` will be saved. It is not quoted because Dapr's API will internally parse the JSON request +object before saving it. ```JSON [ @@ -47,12 +97,49 @@ In this example, `My Message` will be saved. It is not quoted because Dapr's API ## PubSub +{{< tabs ".NET" "Java" >}} + + +{{% codetab %}} + +```csharp + using var client = (new DaprClientBuilder()).Build(); + await client.PublishEventAsync("MyPubSubName", "TopicName", "My Message"); +``` + +The event is published and the content is serialized to `byte[]` and sent to Dapr sidecar. The subscriber will receive +it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines `data` as String. Dapr SDK also provides a built-in deserializer for +`CloudEvent` object. + +```csharp +public async Task HandleMessage(string message) +{ + //ASP.NET Core will automatically deserialize the UTF-8 encoded bytes to a string + return new Ok(); +} +``` + +or + +```csharp +app.MapPost("/TopicName", [Topic("MyPubSubName", "TopicName")] (string message) => { + return Results.Ok(); +} +``` + +{{% /codetab %}} + + +{{% codetab %}} + ```java DaprClient client = (new DaprClientBuilder()).build(); client.publishEvent("TopicName", "My Message").block(); ``` -The event is published and the content is serialized to `byte[]` and sent to Dapr sidecar. The subscriber will receive it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines `data` as String. Dapr SDK also provides a built-in deserializer for `CloudEvent` object. +The event is published and the content is serialized to `byte[]` and sent to Dapr sidecar. The subscriber will receive +it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines `data` as String. Dapr SDK also provides a built-in deserializer for +`CloudEvent` object. ```java @PostMapping(path = "/TopicName") @@ -62,9 +149,28 @@ The event is published and the content is serialized to `byte[]` and sent to Dap } ``` +{{% /codetab %}} + ## Bindings -In this case, the object is serialized to `byte[]` as well and the input binding receives the raw `byte[]` as-is and deserializes it to the expected object type. +In this case, the object is serialized to `byte[]` as well and the input binding receives the raw `byte[]` as-is and +deserializes it to the expected object type. + +{{< tabs ".NET" "Java" >}} + + +{{% codetab %}} + +* Output binding: +```csharp + using var client = (new DaprClientBuilder()).Build(); + await client.InvokeBindingAsync("sample", "My Message"); +``` + +{{% /codetab %}} + + +{{% codetab %}} * Output binding: ```java @@ -80,15 +186,49 @@ In this case, the object is serialized to `byte[]` as well and the input binding System.out.println(message); } ``` + +{{% /codetab %}} + 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, +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. + +{{< tabs ".NET" "Java" >}} + +The .NET SDK supports two different serialization types based on whether you're using the strongly-typed (DataContracts) +or weakly-typed (DataContracts or System.Text.JSON) actor client. [This document]({{< ref dotnet-actors-serialization >}}) +can provide more information about the differences between each and additional considerations to keep in mind. -For Actor's methods, the SDK only supports methods with zero or one parameter. + +{{% codetab %}} + +* Invoking an Actor's method using the weakly-typed client and System.Text.JSON: +```csharp + var proxy = this.ProxyFactory.Create(ActorId.CreateRandom(), "DemoActor"); + await proxy.SayAsync("My message"); +``` + +* Implementing an Actor's method: +```csharp +public Task SayAsync(string message) +{ + Console.WriteLine(message); + return Task.CompletedTask; +} +``` + +{{% /codetab %}} + + +{{% codetab %}} * Invoking an Actor's method: ```java @@ -105,13 +245,37 @@ public String say(String something) { return "OK"; } ``` + +{{% /codetab %}} + It should print: ``` My Message ``` ## Actor's state management -Actors can also have state. In this case, the state manager will serialize and deserialize the objects using the state serializer and handle it transparently to the application. +Actors can also have state. In this case, the state manager will serialize and deserialize the objects using the state +serializer and handle it transparently to the application. + + +{{% codetab %}} + +```csharp +public Task SayAsync(string message) +{ + // Reads state from a key + var previousMessage = await this.StateManager.GetStateAsync("lastmessage"); + + // Sets the new state for the key after serializing it + await this.StateManager.SetStateAsync("lastmessage", message); + return previousMessage; +} +``` + +{{% /codetab %}} + + +{{% codetab %}} ```java public String actorMethod(String message) { @@ -124,12 +288,17 @@ public String actorMethod(String message) { } ``` +{{% /codetab %}} + ## Default serializer The default serializer for Dapr is a JSON serializer with the following expectations: -1. Use of basic [JSON data types](https://www.w3schools.com/js/js_json_datatypes.asp) for cross-language and cross-platform compatibility: string, number, array, boolean, null and another JSON object. Every complex property type in application's serializable objects (DateTime, for example), should be represented as one of the JSON's basic types. -2. Data persisted with the default serializer should be saved as JSON objects too, without extra quotes or encoding. The example below shows how a string and a JSON object would look like in a Redis store. +1. Use of basic [JSON data types](https://www.w3schools.com/js/js_json_datatypes.asp) for cross-language and cross-platform compatibility: string, number, array, +boolean, null and another JSON object. Every complex property type in application's serializable objects (DateTime, +for example), should be represented as one of the JSON's basic types. +2. Data persisted with the default serializer should be saved as JSON objects too, without extra quotes or encoding. +The example below shows how a string and a JSON object would look like in a Redis store. ```bash redis-cli MGET "ActorStateIT_StatefulActorService||StatefulActorTest||1581130928192||message "This is a message to be saved and retrieved." @@ -140,7 +309,8 @@ redis-cli MGET "ActorStateIT_StatefulActorService||StatefulActorTest||1581130928 ``` 3. Custom serializers must serialize object to `byte[]`. 4. Custom serializers must deserialize `byte[]` to object. -5. When user provides a custom serializer, it should be transferred or persisted as `byte[]`. When persisting, also encode as Base64 string. This is done natively by most JSON libraries. +5. When user provides a custom serializer, it should be transferred or persisted as `byte[]`. When persisting, also +encode as Base64 string. This is done natively by most JSON libraries. ```bash redis-cli MGET "ActorStateIT_StatefulActorService||StatefulActorTest||1581130928192||message "VGhpcyBpcyBhIG1lc3NhZ2UgdG8gYmUgc2F2ZWQgYW5kIHJldHJpZXZlZC4=" @@ -149,5 +319,3 @@ redis-cli MGET "ActorStateIT_StatefulActorService||StatefulActorTest||1581130928 redis-cli MGET "ActorStateIT_StatefulActorService||StatefulActorTest||1581130928192||mydata "eyJ2YWx1ZSI6Ik15IGRhdGEgdmFsdWUuIn0=" ``` - -*As of now, the [Java SDK](https://github.com/dapr/java-sdk/) is the only Dapr SDK that implements this specification. In the near future, other SDKs will also implement the same.* From d062507940ca1d7dfbd3014df87bcbf96279669c Mon Sep 17 00:00:00 2001 From: Mark Fussell Date: Sat, 12 Apr 2025 21:48:47 +0100 Subject: [PATCH 02/14] Update sdk-serialization.md Updated formatting and grammar Signed-off-by: Mark Fussell --- .../local-development/sdk-serialization.md | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 0652f7c65f3..835f8d93929 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -8,14 +8,12 @@ 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. -| Language | Default Serializer | +| Language SDK | Default Serializer | |------------------------------|------------------------------------------------------------------------------------------------------------| -| [.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) | +| [.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 | ## Service invocation @@ -42,7 +40,7 @@ In the Java SDK, it is the [DefaultObjectSerializer](https://dapr.github.io/java {{% /codetab %}} -In the example above, the app will receive a `POST` request for the `saySomething` method with the request payload as +In the example above, the app receives 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. ```text @@ -83,7 +81,7 @@ Content-Length: 12 {{% /codetab %}} -In this example, `My Message` will be saved. It is not quoted because Dapr's API will internally parse the JSON request +In this example, `My Message` is saved. It is not quoted because Dapr's API internally parse the JSON request object before saving it. ```JSON @@ -107,14 +105,12 @@ object before saving it. await client.PublishEventAsync("MyPubSubName", "TopicName", "My Message"); ``` -The event is published and the content is serialized to `byte[]` and sent to Dapr sidecar. The subscriber will receive -it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines `data` as String. Dapr SDK also provides a built-in deserializer for -`CloudEvent` object. +The event is published and the content is serialized to `byte[]` and sent to Dapr sidecar. The subscriber receives it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines `data` as String. The Dapr SDK also provides a built-in deserializer for `CloudEvent` object. ```csharp public async Task HandleMessage(string message) { - //ASP.NET Core will automatically deserialize the UTF-8 encoded bytes to a string + //ASP.NET Core automatically deserialize the UTF-8 encoded bytes to a string return new Ok(); } ``` @@ -137,9 +133,7 @@ app.MapPost("/TopicName", [Topic("MyPubSubName", "TopicName")] (string message) client.publishEvent("TopicName", "My Message").block(); ``` -The event is published and the content is serialized to `byte[]` and sent to Dapr sidecar. The subscriber will receive -it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines `data` as String. Dapr SDK also provides a built-in deserializer for -`CloudEvent` object. +The event is published and the content is serialized to `byte[]` and sent to Dapr sidecar. The subscriber receives it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines `data` as String. Dapr SDK also provides a built-in deserializer for `CloudEvent` object. ```java @PostMapping(path = "/TopicName") @@ -153,8 +147,7 @@ it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines ` ## Bindings -In this case, the object is serialized to `byte[]` as well and the input binding receives the raw `byte[]` as-is and -deserializes it to the expected object type. +In this case, the object is serialized to `byte[]` as well and the input binding receives the raw `byte[]` as-is and deserializes it to the expected object type. {{< tabs ".NET" "Java" >}} From 4ab5a6faa181a006b5084e15e58626923818e587 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 18:07:37 -0500 Subject: [PATCH 03/14] Update daprdocs/content/en/developing-applications/local-development/sdk-serialization.md Co-authored-by: Alice Gibbons Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 835f8d93929..1883d1e99a0 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -8,7 +8,7 @@ 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. +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 | |------------------------------|------------------------------------------------------------------------------------------------------------| From e16009a950a3675eb15c0aac6c1596cf71a4dc19 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 18:09:24 -0500 Subject: [PATCH 04/14] Update daprdocs/content/en/developing-applications/local-development/sdk-serialization.md Co-authored-by: Alice Gibbons Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 1883d1e99a0..bb4f0fd1adb 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -40,7 +40,7 @@ Dapr SDKs provide serialization for two use cases. First, for API objects sent t {{% /codetab %}} -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 `"My Message"` - quoted since the serializer will serialize the input String to JSON. ```text From e105212ef9423a03cee3c57841fee7f7fcb03d3d Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 18:10:52 -0500 Subject: [PATCH 05/14] Update daprdocs/content/en/developing-applications/local-development/sdk-serialization.md Co-authored-by: Alice Gibbons Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index bb4f0fd1adb..7e48b27c328 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -188,7 +188,7 @@ My Message ``` ## Actor Method invocation -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. From a5384a12e02f1cd3bf88990477273c4cff047c0d Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 18:11:06 -0500 Subject: [PATCH 06/14] Update daprdocs/content/en/developing-applications/local-development/sdk-serialization.md Co-authored-by: Alice Gibbons Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 7e48b27c328..8afcf574eae 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -192,7 +192,7 @@ Object serialization and deserialization for Actor method invocation are same as 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. +For Actor methods, the SDK only supports methods with zero or one parameter. {{< tabs ".NET" "Java" >}} From 31ca816b859a38afb5ad1c2837d0ffb15743bac8 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 18:16:58 -0500 Subject: [PATCH 07/14] Updated serialization package links + added reference to actor serialization documentation Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 8afcf574eae..3bf37776839 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -10,11 +10,11 @@ aliases: 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 | | -| [Java]({{< ref java >}}) | [DefaultObjectSerializer](https://dapr.github.io/java-sdk/io/dapr/serializer/DefaultObjectSerializer.html) for JSON serialization| -| [JavaScript]({{< ref js >}}) | JSON | +| Language SDK | Default Serializer | +|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| [.NET]({{< ref dotnet >}}) | [DataContracts](https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts) for remoted actors, [System.Text.Json](https://www.nuget.org/packages/System.Text.Json) otherwise. Read more about .NET serialization [here]({{< ref dotnet-actors-serialization >}}) | | +| [Java]({{< ref java >}}) | [DefaultObjectSerializer](https://dapr.github.io/java-sdk/io/dapr/serializer/DefaultObjectSerializer.html) for JSON serialization | +| [JavaScript]({{< ref js >}}) | JSON | ## Service invocation From 4029fb91cb826635b34a4a92dce4b2e9e838309a Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 18:26:10 -0500 Subject: [PATCH 08/14] Added input binding examples for .NET Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 3bf37776839..279f26ce936 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -160,6 +160,29 @@ In this case, the object is serialized to `byte[]` as well and the input binding await client.InvokeBindingAsync("sample", "My Message"); ``` +* Input binding (controllers): +```csharp + [ApiController] + public class SampleController : ControllerBase + { + [HttpPost("propagate")] + public ActionResult GetValue([FromBody] int itemId) + { + Console.WriteLine($"Received message: {itemId}"); + return $"itemID:{itemId}"; + } + } + ``` + +* Input binding (minimal API): +```csharp +app.MapPost("value", ([FromBody] int itemId) => +{ + Console.WriteLine($"Received message: {itemId}"); + return ${itemID:{itemId}"; +}); +* ``` + {{% /codetab %}} From daf4248b08d461f0ff4a0ce8acc6cdc544fe52be Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 19:09:37 -0500 Subject: [PATCH 09/14] Update daprdocs/content/en/developing-applications/local-development/sdk-serialization.md Co-authored-by: Alice Gibbons Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 279f26ce936..9603642071e 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -110,7 +110,7 @@ The event is published and the content is serialized to `byte[]` and sent to Dap ```csharp public async Task HandleMessage(string message) { - //ASP.NET Core automatically deserialize the UTF-8 encoded bytes to a string + //ASP.NET Core automatically deserializes the UTF-8 encoded bytes to a string return new Ok(); } ``` From 8db9133d11e482f6f5a9394fdb4f0c8bc247e34f Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 19:10:03 -0500 Subject: [PATCH 10/14] Update daprdocs/content/en/developing-applications/local-development/sdk-serialization.md Co-authored-by: Alice Gibbons Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 9603642071e..9994196a464 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -133,7 +133,7 @@ app.MapPost("/TopicName", [Topic("MyPubSubName", "TopicName")] (string message) client.publishEvent("TopicName", "My Message").block(); ``` -The event is published and the content is serialized to `byte[]` and sent to Dapr sidecar. The subscriber receives it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines `data` as String. Dapr SDK also provides a built-in deserializer for `CloudEvent` object. +The event is published and the content is serialized to `byte[]` and sent to Dapr sidecar. The subscriber receives it as a [CloudEvent](https://github.com/cloudevents/spec). Cloud event defines `data` as String. The Dapr SDK also provides a built-in deserializer for `CloudEvent` objects. ```java @PostMapping(path = "/TopicName") From f6c7ffa7ecb5282bfaa9f552a1467e3925494977 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 19:10:20 -0500 Subject: [PATCH 11/14] Update daprdocs/content/en/developing-applications/local-development/sdk-serialization.md Co-authored-by: Alice Gibbons Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 9994196a464..a1370c73c4c 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -147,7 +147,7 @@ The event is published and the content is serialized to `byte[]` and sent to Dap ## Bindings -In this case, the object is serialized to `byte[]` as well and the input binding receives the raw `byte[]` as-is and deserializes it to the expected object type. +For output bindings the object is serialized to `byte[]` whereas the input binding receives the raw `byte[]` as-is and deserializes it to the expected object type. {{< tabs ".NET" "Java" >}} From 3c6fa2280a5257668965c5df0ec9d1213214c69a Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Fri, 18 Apr 2025 19:10:44 -0500 Subject: [PATCH 12/14] Update daprdocs/content/en/developing-applications/local-development/sdk-serialization.md Co-authored-by: Alice Gibbons Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index a1370c73c4c..45576952d39 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -219,7 +219,7 @@ 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) +The .NET SDK supports two different serialization types based on whether you're using strongly-typed (DataContracts) or weakly-typed (DataContracts or System.Text.JSON) actor client. [This document]({{< ref dotnet-actors-serialization >}}) can provide more information about the differences between each and additional considerations to keep in mind. From e33317768f38aea953318da1be34cdfd06f95572 Mon Sep 17 00:00:00 2001 From: Mark Fussell Date: Mon, 21 Apr 2025 13:03:33 +0100 Subject: [PATCH 13/14] Update daprdocs/content/en/developing-applications/local-development/sdk-serialization.md Signed-off-by: Mark Fussell --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 45576952d39..06305f8820c 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -12,7 +12,7 @@ Dapr SDKs provide serialization for two use cases. First, for API objects sent t | Language SDK | Default Serializer | |------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| [.NET]({{< ref dotnet >}}) | [DataContracts](https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/using-data-contracts) for remoted actors, [System.Text.Json](https://www.nuget.org/packages/System.Text.Json) otherwise. Read more about .NET serialization [here]({{< ref dotnet-actors-serialization >}}) | | +| [.NET]({{< ref dotnet >}}) | [DataContracts](https://learn.microsoft.com/dotnet/framework/wcf/feature-details/using-data-contracts) for remoted actors, [System.Text.Json](https://www.nuget.org/packages/System.Text.Json) otherwise. Read more about .NET serialization [here]({{< ref dotnet-actors-serialization >}}) | | | [Java]({{< ref java >}}) | [DefaultObjectSerializer](https://dapr.github.io/java-sdk/io/dapr/serializer/DefaultObjectSerializer.html) for JSON serialization | | [JavaScript]({{< ref js >}}) | JSON | From 7d2e80c0de94bfb290ed328a90e83e3cd87fff05 Mon Sep 17 00:00:00 2001 From: Whit Waldo Date: Tue, 22 Apr 2025 19:46:13 -0500 Subject: [PATCH 14/14] Updated to use the correct method for service invocation Signed-off-by: Whit Waldo --- .../local-development/sdk-serialization.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md index 06305f8820c..172fab4cc77 100644 --- a/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md +++ b/daprdocs/content/en/developing-applications/local-development/sdk-serialization.md @@ -35,7 +35,7 @@ Dapr SDKs provide serialization for two use cases. First, for API objects sent t ```java DaprClient client = (new DaprClientBuilder()).build(); - client.invokeService("myappid", "saySomething", "My Message", HttpExtension.POST).block(); + client.invokeMethod("myappid", "saySomething", "My Message", HttpExtension.POST).block(); ``` {{% /codetab %}}