Skip to content

Commit 205d170

Browse files
committed
Update serialization docs
1 parent 620a557 commit 205d170

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

docs/serialization.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@ The default behavior of RestSharp is to swallow deserialization errors and retur
77
property of the response. Read more about it in the [Error Handling](error-handling.md).
88
:::
99

10+
You can tell RestSharp to use a custom serializer by using the `configureSerialization` constructor parameter:
11+
12+
```csharp
13+
var client = new RestClient(
14+
options,
15+
configureSerialization: s => s.UseSerializer(() => new CustomSerializer());
16+
);
17+
```
18+
1019
## JSON
1120

1221
The default JSON serializer uses `System.Text.Json`, which is a part of .NET since .NET 6. For earlier versions, it is added as a dependency. There are also a few serializers provided as additional packages.
1322

1423
By default, RestSharp will use `JsonSerializerDefaults.Web` configuration. If necessary, you can specify your own options:
1524

1625
```csharp
17-
client.UseSystemTextJson(new JsonSerializerOptions {...});
26+
var client = new RestClient(
27+
options,
28+
configureSerialization: s => s.UseSystemTextJson(new JsonSerializerOptions {...})
29+
);
1830
```
1931

2032
## XML
@@ -43,7 +55,10 @@ Please note that `RestSharp.Newtonsoft.Json` package is not provided by RestShar
4355
Use the extension method provided by the package to configure the client:
4456

4557
```csharp
46-
client.UseNewtonsoftJson();
58+
var client = new RestClient(
59+
options,
60+
configureSerialization: s => s.UseNewtonsoftJson()
61+
);
4762
```
4863

4964
The serializer configures some options by default:

0 commit comments

Comments
 (0)