-
Notifications
You must be signed in to change notification settings - Fork 323
fix(data handling): updated data handling docs #4928
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
80a9b4d
fix(data handling): updated java data handling docs
flippedcoder fe7aa5b
fix(data handling): updated typescript data handling docs; moved cont…
flippedcoder 846b90d
fix(data handling): updated and separated dotnet data handling pages
flippedcoder f6820d4
fix(data handling): updated and separated ruby data handling pages
flippedcoder 803b712
chore(configs): added new redirects
flippedcoder 70339bf
chore(configs): fixed broken links
flippedcoder 2096fab
Merge branch 'main' into mm/data-handling
Duncanma ef13e09
Merge branch 'main' into mm/data-handling
flippedcoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
docs/develop/dotnet/best-practices/data-handling/data-conversion.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| id: data-conversion | ||
| title: Payload conversion - .NET SDK | ||
| sidebar_label: Payload conversion | ||
| toc_max_heading_level: 3 | ||
| tags: | ||
| - Data Converters | ||
| - .NET SDK | ||
| - Temporal SDKs | ||
| description: Customize how Temporal serializes application objects using Payload Converters in the .NET SDK. | ||
| --- | ||
|
|
||
| import { CaptionedImage } from '@site/src/components'; | ||
|
|
||
| ## Payload conversion | ||
|
|
||
| Temporal SDKs provide a default [Payload Converter](/payload-converter) that can be customized to convert a custom data type to [Payload](/dataconversion#payload) and back. | ||
|
|
||
| ### Conversion sequence {/* #conversion-sequence */} | ||
|
|
||
| The order in which your encoding Payload Converters are applied depend on the order given to the Data Converter. | ||
| You can set multiple encoding Payload Converters to run your conversions. | ||
| When the Data Converter receives a value for conversion, it passes through each Payload Converter in sequence until the converter that handles the data type does the conversion. | ||
|
|
||
| Payload Converters can be customized independently of a Payload Codec. | ||
| Temporal's Converter architecture looks like this: | ||
|
|
||
| <CaptionedImage | ||
| src="/img/info/converter-architecture.png" | ||
| title="Temporal converter architecture" | ||
| /> | ||
|
|
||
| ## Custom Payload Converter {/* #custom-payload-converter */} | ||
|
|
||
| Data converters are used to convert raw Temporal payloads to/from actual .NET types. | ||
| A custom data converter can be set via the `DataConverter` option when creating a client. Data converters are a combination of payload converters, payload codecs, and failure converters. | ||
| Payload converters convert .NET values to/from serialized bytes. Payload codecs convert bytes to bytes (e.g. for compression or encryption). Failure converters convert exceptions to/from serialized failures. | ||
|
|
||
| Data converters are in the `Temporalio.Converters` namespace. | ||
| The default data converter uses a default payload converter, which supports the following types: | ||
|
|
||
| - `null` | ||
| - `byte[]` | ||
| - `Google.Protobuf.IMessage` instances | ||
| - Anything that `System.Text.Json` supports | ||
| - `IRawValue` as unconverted raw payloads | ||
|
|
||
| Custom converters can be created for all uses. For example, to create client with a data converter that converts all C# | ||
| property names to camel case, you would: | ||
|
|
||
| ```csharp | ||
| using System.Text.Json; | ||
| using Temporalio.Client; | ||
| using Temporalio.Converters; | ||
|
|
||
| public class CamelCasePayloadConverter : DefaultPayloadConverter | ||
| { | ||
| public CamelCasePayloadConverter() | ||
| : base(new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }) | ||
| { | ||
| } | ||
| } | ||
|
|
||
| var client = await TemporalClient.ConnectAsync(new() | ||
| { | ||
| TargetHost = "localhost:7233", | ||
| Namespace = "my-namespace", | ||
| DataConverter = DataConverter.Default with { PayloadConverter = new CamelCasePayloadConverter() }, | ||
| }); | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
docs/develop/dotnet/best-practices/data-handling/index.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| --- | ||
| id: data-handling | ||
| title: Data handling - .NET SDK | ||
| sidebar_label: Data handling | ||
| description: | ||
| Learn how Temporal handles data through the Data Converter, including payload conversion, encryption, and large | ||
| payload storage. | ||
| toc_max_heading_level: 3 | ||
| tags: | ||
| - .NET SDK | ||
| - Temporal SDKs | ||
| - Data Converters | ||
| --- | ||
|
|
||
| import { CaptionedImage } from '@site/src/components'; | ||
|
|
||
| All data sent to and from the Temporal Service passes through the **Data Converter**. The Data Converter has three | ||
| layers that handle different concerns: | ||
|
|
||
| <CaptionedImage | ||
| src="/diagrams/data-converter-flow-with-external-storage.svg" | ||
| srcDark="/diagrams/data-converter-flow-dark.svg" | ||
| title="The Flow of Data through a Data Converter" | ||
| alt="The Flow of Data through a Data Converter" | ||
| /> | ||
|
|
||
| Of these three layers, only the PayloadConverter is required. Temporal uses a default PayloadConverter that handles JSON | ||
| serialization. The PayloadCodec and ExternalStorage layers are optional. You only need to customize these layers when | ||
| your application requires non-JSON types, encryption, or payload offloading. | ||
|
|
||
| | | [PayloadConverter](/develop/dotnet/best-practices/data-handling/data-conversion) | [PayloadCodec](/develop/dotnet/best-practices/data-handling/data-encryption) | | ||
| | ------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------- | | ||
| | **Purpose** | Serialize application data to bytes | Transform encoded payloads (encrypt, compress) | | ||
| | **Default** | JSON serialization | None (passthrough) | | ||
|
|
||
| For a deeper conceptual explanation, see the [Data Conversion encyclopedia](/dataconversion) and [External Storage](/external-storage). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
docs/develop/java/best-practices/data-handling/data-conversion.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| --- | ||
| id: data-conversion | ||
| title: Payload conversion - Java SDK | ||
| sidebar_label: Payload conversion | ||
| toc_max_heading_level: 3 | ||
| tags: | ||
| - Data Converters | ||
| - Java SDK | ||
| - Temporal SDKs | ||
| description: Customize how Temporal serializes application objects using Payload Converters in the Java SDK. | ||
| --- | ||
|
|
||
| import { CaptionedImage } from '@site/src/components'; | ||
|
|
||
| Payload Converters serialize your application objects into a `Payload` and deserialize them back. | ||
| A `Payload` is a binary form with metadata that Temporal uses to transport data. | ||
|
|
||
| By default, Temporal uses a Payload Converter that handles `null`, byte arrays, protobuf messages, and anything JSON-serializable. | ||
| You only need a custom Payload Converter when your application uses types that aren't natively supported. | ||
|
|
||
| ## Default supported types | ||
|
|
||
| The default Data Converter supports converting multiple types including: | ||
|
|
||
| - `null` | ||
| - Byte arrays | ||
| - Protobuf JSON: if a value is an instance of a Protobuf message, it is encoded with proto3 JSON | ||
| - [Jackson JSON](https://docs.spring.io/spring-framework/reference/web/webmvc/mvc-controller/ann-methods/jackson.html) | ||
| - Anything that can be converted to JSON | ||
|
|
||
| ## Using custom Payload conversion {/* #custom-payload-conversion */} | ||
|
|
||
| Temporal SDKs provide a [Payload Converter](/payload-converter) that can be customized to convert a custom data type to [Payload](/dataconversion#payload) and back. | ||
|
|
||
| Implementing custom Payload conversion is optional. | ||
| It is needed only if the [default Data Converter](/default-custom-data-converters#default-data-converter) does not support your custom values. | ||
|
|
||
| To support custom Payload conversion, create a [custom Payload Converter](/payload-converter#composite-data-converters) and configure the Data Converter to use it in your Client options. | ||
|
|
||
| The order in which your encoding Payload Converters are applied depend on the order given to the Data Converter. | ||
| You can set multiple encoding Payload Converters to run your conversions. | ||
| When the Data Converter receives a value for conversion, it passes through each Payload Converter in sequence until the converter that handles the data type does the conversion. | ||
|
|
||
| Payload Converters can be customized independently of a Payload Codec. | ||
| Temporal's Converter architecture looks like this: | ||
|
|
||
| <CaptionedImage | ||
| src="/img/info/converter-architecture.png" | ||
| title="Temporal converter architecture" | ||
| /> | ||
|
|
||
| Create a custom implementation of a [PayloadConverter](https://www.javadoc.io/doc/io.temporal/temporal-sdk/latest/io/temporal/common/converter/PayloadConverter.html) interface and use the `withPayloadConverterOverrides` method to implement the custom object conversion with `DefaultDataConverter`. | ||
|
|
||
| `PayloadConverter` serializes and deserializes method parameters that need to be sent over the wire. | ||
| You can create a custom implementation of `PayloadConverter` for custom formats, as shown in the following example: | ||
|
|
||
| ```java | ||
| /** Payload Converter specific to your custom object */ | ||
| public class YourCustomPayloadConverter implements PayloadConverter { | ||
| //... | ||
| @Override | ||
| public String getEncodingType() { | ||
| return "json/plain"; // The encoding type determines which default conversion behavior to override. | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<Payload> toData(Object value) throws DataConverterException { | ||
| // Add your convert-to logic here. | ||
| } | ||
|
|
||
| @Override | ||
| public <T> T fromData(Payload content, Class<T> valueClass, Type valueType) | ||
| throws DataConverterException { | ||
| // Add your convert-from logic here. | ||
| } | ||
| //... | ||
| } | ||
| ``` | ||
|
|
||
| You can also use [specific implementation classes](https://www.javadoc.io/static/io.temporal/temporal-sdk/1.18.1/io/temporal/common/converter/package-summary.html) provided in the Java SDK. | ||
|
|
||
| For example, to create a custom `JacksonJsonPayloadConverter`, use the following: | ||
|
|
||
| ```java | ||
| //... | ||
| private static JacksonJsonPayloadConverter yourCustomJacksonJsonPayloadConverter() { | ||
| ObjectMapper objectMapper = new ObjectMapper(); | ||
| // Add your custom logic here. | ||
| return new JacksonJsonPayloadConverter(objectMapper); | ||
| } | ||
| //... | ||
| ``` | ||
|
|
||
| To set your custom Payload Converter, use it with [withPayloadConverterOverrides](https://www.javadoc.io/doc/io.temporal/temporal-sdk/latest/io/temporal/common/converter/DefaultDataConverter.html#withPayloadConverterOverrides(io.temporal.common.converter.PayloadConverter...)) with a new instance of `DefaultDataConverter` in your `WorkflowClient` options that you use in your Worker process and to start your Workflow Executions. | ||
|
|
||
| The following example shows how to set a custom `YourCustomPayloadConverter` Payload Converter. | ||
|
|
||
| ```java | ||
| //... | ||
| DefaultDataConverter ddc = | ||
| DefaultDataConverter.newDefaultInstance() | ||
| .withPayloadConverterOverrides(new YourCustomPayloadConverter()); | ||
|
|
||
| WorkflowClientOptions workflowClientOptions = | ||
| WorkflowClientOptions.newBuilder().setDataConverter(ddc).build(); | ||
| //... | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.