Skip to content

Commit abf4d3a

Browse files
authored
JSON source gen breaking change (#26222)
1 parent f8cee81 commit abf4d3a

File tree

6 files changed

+63
-6
lines changed

6 files changed

+63
-6
lines changed

.openpublishing.redirection.json

+5
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@
250250
"source_path": "docs/core/compatibility/code-analysis.md",
251251
"redirect_url": "/dotnet/core/compatibility/code-analysis/5.0/ca1416-platform-compatibility-analyzer"
252252
},
253+
{
254+
"source_path": "docs/core/compatibility/core-libraries/6.0/jsonserializer-source-generator-overloads.md",
255+
"redirect_url": "/dotnet/core/compatibility/serialization/6.0/jsonserializer-source-generator-overloads",
256+
"redirect_document_id": true
257+
},
253258
{
254259
"source_path": "docs/core/compatibility/interop.md",
255260
"redirect_url": "/dotnet/core/compatibility/interop/5.0/built-in-support-for-winrt-removed"

docs/core/compatibility/6.0.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ If you're migrating an app to .NET 6, the breaking changes listed here might aff
4747
| [FileStream no longer synchronizes file offset with OS](core-libraries/6.0/filestream-doesnt-sync-offset-with-os.md) | Preview 4 |
4848
| [FileStream.Position updates after ReadAsync or WriteAsync completes](core-libraries/6.0/filestream-position-updates-after-readasync-writeasync-completion.md) | Preview 4 |
4949
| [New diagnostic IDs for obsoleted APIs](core-libraries/6.0/diagnostic-id-change-for-obsoletions.md) | Preview 5 |
50-
| [New JsonSerializer source generator overloads](core-libraries/6.0/jsonserializer-source-generator-overloads.md) | Preview 6 |
5150
| [New nullable annotation in AssociatedMetadataTypeTypeDescriptionProvider](core-libraries/6.0/nullable-ref-type-annotations-added.md) | RC 2 |
5251
| [New System.Linq.Queryable method overloads](core-libraries/6.0/additional-linq-queryable-method-overloads.md) | Preview 3-4 |
5352
| [Older framework versions dropped from package](core-libraries/6.0/older-framework-versions-dropped.md) | Preview 5 |
@@ -106,7 +105,9 @@ If you're migrating an app to .NET 6, the breaking changes listed here might aff
106105

107106
| Title | Preview introduced |
108107
| - | - |
108+
| [JSON source-generation API refactoring](serialization/6.0/json-source-gen-api-refactor.md) | RC 2 |
109109
| [JsonNode no longer supports C# `dynamic` type](serialization/6.0/jsonnode-dynamic-type.md) | Preview 7 |
110+
| [New JsonSerializer source generator overloads](serialization/6.0/jsonserializer-source-generator-overloads.md) | Preview 6 |
110111

111112
## Windows Forms
112113

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: "Breaking change: JSON source-generation API refactoring"
3+
description: Learn about the .NET 6.0 breaking change where the APIs called by JSON source generator output were refactored.
4+
ms.date: 09/22/2021
5+
---
6+
# JSON source-generation API refactoring
7+
8+
The APIs that the output of the JSON source generator calls have been refactored. The refactoring makes them easier to extend with new features in the future. Projects that explicitly use the JSON source generator and were compiled with .NET 6 RC 1 or earlier will fail with run-time exceptions when run on the .NET 6 RC 2 runtime.
9+
10+
## Previous behavior
11+
12+
Projects that were compiled using the .NET 6 RC 1 or earlier version of the System.Text.Json source generator and library run as expected.
13+
14+
## New behavior
15+
16+
Projects that were compiled using the .NET 6 RC 1 version of the System.Text.Json source generator and library fail when run against the .NET 6 RC 2 runtime. Projects that are recompiled with the RC 2 SDK work as expected.
17+
18+
## Version introduced
19+
20+
6.0 RC 2
21+
22+
## Type of breaking change
23+
24+
This change can affect [binary compatibility](../../categories.md#binary-compatibility).
25+
26+
## Reason for change
27+
28+
This change was introduced to make it easier to extend the source-generator implementation with features in the future. For more information, see [dotnet/runtime#59243](https://github.com/dotnet/runtime/pull/59243).
29+
30+
## Recommended action
31+
32+
Recompile your app using the RC 2 SDK.
33+
34+
## Affected APIs
35+
36+
- <xref:System.Text.Json.Serialization.JsonSerializerContext?displayProperty=fullName>
37+
- <xref:System.Text.Json.Serialization.JsonSerializableAttribute?displayProperty=fullName>
38+
- <xref:System.Text.Json.Serialization.JsonSourceGenerationOptionsAttribute?displayProperty=fullName>
39+
- <xref:System.Text.Json.Serialization.Metadata?displayProperty=fullName> (not intended for direct use)
40+
41+
## See also
42+
43+
- [How to use source generation in System.Text.Json](../../../../standard/serialization/system-text-json-source-generation.md)

docs/core/compatibility/toc.yml

+12-4
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ items:
7777
href: core-libraries/6.0/filestream-position-updates-after-readasync-writeasync-completion.md
7878
- name: New diagnostic IDs for obsoleted APIs
7979
href: core-libraries/6.0/diagnostic-id-change-for-obsoletions.md
80-
- name: New JsonSerializer source generator overloads
81-
href: core-libraries/6.0/jsonserializer-source-generator-overloads.md
8280
- name: New nullable annotation in AssociatedMetadataTypeTypeDescriptionProvider
8381
href: core-libraries/6.0/nullable-ref-type-annotations-added.md
8482
- name: New Queryable method overloads
@@ -139,6 +137,14 @@ items:
139137
href: sdk/6.0/outputtype-not-set-automatically.md
140138
- name: RuntimeIdentifier warning if self-contained is unspecified
141139
href: sdk/6.0/runtimeidentifier-self-contained.md
140+
- name: Serialization
141+
items:
142+
- name: JSON source-generation API refactoring
143+
href: serialization/6.0/json-source-gen-api-refactor.md
144+
- name: JsonNode no longer supports C# `dynamic`
145+
href: serialization/6.0/jsonnode-dynamic-type.md
146+
- name: New JsonSerializer source generator overloads
147+
href: serialization/6.0/jsonserializer-source-generator-overloads.md
142148
- name: Windows Forms
143149
items:
144150
- name: APIs throw ArgumentNullException
@@ -579,8 +585,6 @@ items:
579585
href: core-libraries/6.0/filestream-position-updates-after-readasync-writeasync-completion.md
580586
- name: New diagnostic IDs for obsoleted APIs
581587
href: core-libraries/6.0/diagnostic-id-change-for-obsoletions.md
582-
- name: New JsonSerializer source generator overloads
583-
href: core-libraries/6.0/jsonserializer-source-generator-overloads.md
584588
- name: New nullable annotation in AssociatedMetadataTypeTypeDescriptionProvider
585589
href: core-libraries/6.0/nullable-ref-type-annotations-added.md
586590
- name: New Queryable method overloads
@@ -803,8 +807,12 @@ items:
803807
items:
804808
- name: .NET 6
805809
items:
810+
- name: JSON source-generation API refactoring
811+
href: serialization/6.0/json-source-gen-api-refactor.md
806812
- name: JsonNode no longer supports C# `dynamic`
807813
href: serialization/6.0/jsonnode-dynamic-type.md
814+
- name: New JsonSerializer source generator overloads
815+
href: serialization/6.0/jsonserializer-source-generator-overloads.md
808816
- name: .NET 5
809817
items:
810818
- name: BinaryFormatter.Deserialize rewraps exceptions

docs/standard/serialization/system-text-json-source-generation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The following table shows which options specified by `JsonSerializerOptions` are
6868
| <xref:System.Text.Json.JsonSerializerOptions.ReferenceHandler> ||
6969
| <xref:System.Text.Json.JsonSerializerOptions.WriteIndented> \* | ✔️ |
7070

71-
\* Some `Serialize` methods let you pass in a `Utf8JsonWriter` instance. In that case, you can set the `Encoder` and `WriteIndented` options by using <xref:System.Text.Json.JsonWriterOptions.Indented?displayProperty=nameWithType> and <xref:System.Text.Json.JsonWriterOptions.Indented?displayProperty=nameWithType>.
71+
\* Some `Serialize` methods let you pass in a `Utf8JsonWriter` instance. In that case, you can set the `Encoder` and `WriteIndented` options by using <xref:System.Text.Json.JsonWriterOptions.Encoder?displayProperty=nameWithType> and <xref:System.Text.Json.JsonWriterOptions.Indented?displayProperty=nameWithType>.
7272

7373
The following table shows which attributes are supported by the optimized serialization code:
7474

0 commit comments

Comments
 (0)