Skip to content

Commit b2c48c1

Browse files
authored
Add migration guidance for Newtonsoft.Json JsonObject Title property (#48213)
1 parent 95dcc71 commit b2c48c1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/standard/serialization/system-text-json/migrate-from-newtonsoft.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ In .NET 8 and later versions, you can set your preference for whether to skip or
463463

464464
### JsonObjectAttribute
465465

466-
`Newtonsoft.Json` has an attribute, `JsonObjectAttribute`, that can be applied at the *type level* to control which members are serialized, how `null` values are handled, and whether all members are required. System.Text.Json has no equivalent attribute that can be applied on a type. For some behaviors, such as `null` value handling, you can either configure the same behavior on the global <xref:System.Text.Json.JsonSerializerOptions> or individually on each property.
466+
`Newtonsoft.Json` has an attribute, `JsonObjectAttribute`, that can be applied at the *type level* to control which members are serialized, how `null` values are handled, and whether all members are required. System.Text.Json has no equivalent attribute that can be applied on a type. For some behaviors, such as `null` value handling, you can configure the same behavior either on the global <xref:System.Text.Json.JsonSerializerOptions> or individually on each property using <xref:System.Text.Json.Serialization.JsonIgnoreAttribute>.
467467

468468
Consider the following example that uses `Newtonsoft.Json.JsonObjectAttribute` to specify that all `null` properties should be ignored:
469469

@@ -515,6 +515,15 @@ public class Person
515515
}
516516
```
517517

518+
Finally, consider the following example that uses `Newtonsoft.Json.JsonObjectAttribute` to specify a title for JSON schema generation:
519+
520+
```csharp
521+
[JsonObject(Title = "PersonTitle")]
522+
public class Person { ... }
523+
```
524+
525+
The `Title` property is used for JSON schema metadata and doesn't have a direct equivalent in System.Text.Json. Starting in .NET 9, you can use the <xref:System.Text.Json.Schema.JsonSchemaExporter> to generate JSON schemas and customize the schema title using the <xref:System.Text.Json.Schema.JsonSchemaExporterOptions.TransformSchemaNode%2A> delegate. For an example, see [Transform the generated schema](extract-schema.md#transform-the-generated-schema).
526+
518527
### TraceWriter
519528

520529
`Newtonsoft.Json` lets you debug by using a `TraceWriter` to view logs that are generated by serialization or deserialization. <xref:System.Text.Json?displayProperty=fullName> doesn't do logging.

0 commit comments

Comments
 (0)