Skip to content

Commit 14f513a

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

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
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/resources/attributes.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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#custom-serializer-settings) 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
}

0 commit comments

Comments
 (0)