Skip to content

Commit 1ed87ae

Browse files
author
Bart Koelman
committed
Updated documentation
1 parent e2c94d3 commit 1ed87ae

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

docs/usage/options.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,26 @@ To limit the maximum depth of nested includes, use `MaximumIncludeDepth`. This i
7878
options.MaximumIncludeDepth = 1;
7979
```
8080

81-
## Custom Serializer Settings
81+
## Customize Serializer options
8282

83-
We use [Newtonsoft.Json](https://www.newtonsoft.com/json) for all serialization needs.
84-
If you want to change the default serializer settings, you can:
83+
We use [System.Text.Json](https://www.nuget.org/packages/System.Text.Json) for all serialization needs.
84+
If you want to change the default serializer options, you can:
8585

8686
```c#
87-
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
88-
options.SerializerSettings.Converters.Add(new StringEnumConverter());
89-
options.SerializerSettings.Formatting = Formatting.Indented;
87+
options.SerializerOptions.WriteIndented = true;
88+
options.SerializerOptions.ReferenceHandler = ReferenceHandler.Preserve;
89+
options.SerializerOptions.Converters.Add(new JsonStringEnumConverter());
9090
```
9191

9292
The default naming convention (as used in the routes and resource/attribute/relationship names) is also determined here, and can be changed (default is camel-case):
9393

9494
```c#
95-
options.SerializerSettings.ContractResolver = new DefaultContractResolver
96-
{
97-
NamingStrategy = new KebabCaseNamingStrategy()
98-
};
95+
// Use Pascal case
96+
options.SerializerOptions.PropertyNamingPolicy = null;
97+
options.SerializerOptions.DictionaryKeyPolicy = null;
9998
```
10099

101-
Because we copy resource properties into an intermediate object before serialization, Newtonsoft.Json annotations on properties are ignored.
100+
Because we copy resource properties into an intermediate object before serialization, JSON annotations such as `[JsonPropertyName]` and `[JsonIgnore]` on `[Attr]` properties are ignored.
102101

103102

104103
## Enable ModelState Validation

docs/usage/resource-graph.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,4 @@ public class MyModel : Identifiable
9898
}
9999
```
100100

101-
The default naming convention can be changed in [options](~/usage/options.md#custom-serializer-settings).
101+
The default naming convention can be changed in [options](~/usage/options.md#customize-serializer-options).

docs/usage/resources/attributes.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class Person : Identifiable
1414

1515
There are two ways the exposed attribute name is determined:
1616

17-
1. Using the configured [naming convention](~/usage/options.md#custom-serializer-settings).
17+
1. Using the configured [naming convention](~/usage/options.md#customize-serializer-options).
1818

1919
2. Individually using the attribute's constructor.
2020
```c#
@@ -88,9 +88,9 @@ public class Person : Identifiable
8888
## Complex Attributes
8989

9090
Models may contain complex attributes.
91-
Serialization of these types is done by [Newtonsoft.Json](https://www.newtonsoft.com/json),
92-
so you should use their APIs to specify serialization formats.
93-
You can also use global options to specify `JsonSerializer` configuration.
91+
Serialization of these types is done by [System.Text.Json](https://www.nuget.org/packages/System.Text.Json),
92+
so you should use their APIs to specify serialization format.
93+
You can also use [global options](~/usage/options.md#customize-serializer-options) to control the `JsonSerializer` behavior.
9494

9595
```c#
9696
public class Foo : Identifiable
@@ -101,7 +101,8 @@ public class Foo : Identifiable
101101

102102
public class Bar
103103
{
104-
[JsonProperty("compound-member")]
104+
[JsonPropertyName("compound-member")]
105+
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
105106
public string CompoundMember { get; set; }
106107
}
107108
```
@@ -121,13 +122,13 @@ public class Foo : Identifiable
121122
{
122123
get
123124
{
124-
return Bar == null ? "{}" : JsonConvert.SerializeObject(Bar);
125+
return Bar == null ? "{}" : JsonSerializer.Serialize(Bar);
125126
}
126127
set
127128
{
128129
Bar = string.IsNullOrWhiteSpace(value)
129130
? null
130-
: JsonConvert.DeserializeObject<Bar>(value);
131+
: JsonSerializer.Deserialize<Bar>(value);
131132
}
132133
}
133134
}

docs/usage/resources/relationships.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ The left side of this relationship is of type `Person` (public name: "persons")
3838

3939
There are two ways the exposed relationship name is determined:
4040

41-
1. Using the configured [naming convention](~/usage/options.md#custom-serializer-settings).
41+
1. Using the configured [naming convention](~/usage/options.md#customize-serializer-options).
4242

4343
2. Individually using the attribute's constructor.
4444
```c#

docs/usage/routing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The exposed name of the resource ([which can be customized](~/usage/resource-gra
4545

4646
### Non-JSON:API controllers
4747

48-
If a controller does not inherit from `JsonApiController<TResource>`, the [configured naming convention](~/usage/options.md#custom-serializer-settings) is applied to the name of the controller.
48+
If a controller does not inherit from `JsonApiController<TResource>`, the [configured naming convention](~/usage/options.md#customize-serializer-options) is applied to the name of the controller.
4949

5050
```c#
5151
public class OrderLineController : ControllerBase

0 commit comments

Comments
 (0)