Skip to content

Commit ab5d374

Browse files
author
David R. Williamson
committed
ADT: add info about object serializer override
1 parent e11e630 commit ab5d374

File tree

1 file changed

+22
-2
lines changed
  • sdk/digitaltwins/Azure.DigitalTwins.Core/samples

1 file changed

+22
-2
lines changed

sdk/digitaltwins/Azure.DigitalTwins.Core/samples/Readme.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ The samples project demonstrates the following:
2222

2323
## Creating the digital twins client
2424

25+
### Simple creation
26+
2527
To create a new digital twins client, you need the endpoint to an Azure Digital Twin instance and credentials.
2628
In the sample below, you can set `AdtEndpoint`, `TenantId`, `ClientId`, and `ClientSecret` as command-line arguments.
2729
The client requires an instance of [TokenCredential](https://docs.microsoft.com/dotnet/api/azure.core.tokencredential?view=azure-dotnet).
@@ -40,13 +42,31 @@ var client = new DigitalTwinsClient(
4042
tokenCredential);
4143
```
4244

43-
Also, if you need to override pipeline behavior, such as provide your own HttpClient instance, you can do that via the other constructor that takes a client options.
45+
### Override options
46+
47+
If you need to override pipeline behavior, such as provide your own HttpClient instance, you can do that via the other constructor that takes a
48+
[DigitalTwinsClientOptions](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/digitaltwins/Azure.DigitalTwins.Core/src/DigitalTwinsClientOptions.cs) parameter.
4449
It provides an opportunity to override default behavior including:
4550

46-
- Specifying API version
4751
- Overriding [transport](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Pipeline.md)
4852
- Enabling [diagnostics](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Diagnostics.md)
4953
- Controlling [retry strategy](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/core/Azure.Core/samples/Configuration.md)
54+
- Specifying API version
55+
- Object serializer (see below)
56+
57+
#### Object serializer
58+
59+
The digital twins client has methods that will serialize your custom digital twins and relationship types for transport, and deserialize the response back to a type specified by you.
60+
The default object serializer, [JsonObjectSerializer](https://docs.microsoft.com/dotnet/api/azure.core.serialization.jsonobjectserializer?view=azure-dotnet),
61+
works using the `System.Text.Json` library.
62+
It uses a default [JsonSerializerOptions](https://docs.microsoft.com/dotnet/api/system.text.json.jsonserializeroptions?view=net-5.0) instance.
63+
64+
Set the `Serializer` property to a custom instance of `JsonObjectSerializer` or your own implementation that inherits from
65+
[ObjectSerializer](https://docs.microsoft.com/dotnet/api/azure.core.serialization.objectserializer?view=azure-dotnet).
66+
67+
One reason for customizing would be to provide custom de/serialization settings, for example setting the `IgnoreNullValues` property to `true`.
68+
See more examples and options of working with `JsonSerializerOptions` [here](https://docs.microsoft.com/dotnet/standard/serialization/system-text-json-how-to?pivots=dotnet-5-0#ignore-all-null-value-properties).
69+
This would prevent unset properties on your digital twin or relationship from being included in the payload sent to the service.
5070

5171
## Create, list, decommission, and delete models
5272

0 commit comments

Comments
 (0)