You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix#113
Warn when JsonSerializable is used on TomlSerializerContext and switch the repo, tests, and docs to the dedicated TomlSerializable root attribute. Also add TypeInfoPropertyName parity and remove the SYSLIB1224 suppressions that are no longer needed.
Copy file name to clipboardExpand all lines: site/docs/compatibility.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,11 +44,11 @@ See [Source generation and NativeAOT](source-generation.md) for details.
44
44
45
45
## System.Text.Json interop
46
46
47
-
Tomlyn reuses [`System.Text.Json`](xref:System.Text.Json) types in two areas:
47
+
Tomlyn reuses [`System.Text.Json`](xref:System.Text.Json) types in several areas:
48
48
49
49
-**Naming policies** - [`TomlSerializerOptions.PropertyNamingPolicy`](xref:Tomlyn.TomlSerializerOptions.PropertyNamingPolicy) accepts any [`JsonNamingPolicy`](xref:System.Text.Json.JsonNamingPolicy).
50
50
-**Attributes** - most common [`System.Text.Json.Serialization`](xref:System.Text.Json.Serialization) attributes work out of the box.
51
-
-**Source generation** - [`[JsonSerializable]`](xref:System.Text.Json.Serialization.JsonSerializableAttribute) roots and [`JsonKnownNamingPolicy`](xref:System.Text.Json.JsonKnownNamingPolicy)are used for context declaration.
51
+
-**Source generation** - [`[TomlSerializable]`](xref:Tomlyn.Serialization.TomlSerializableAttribute) roots declare TOML contexts, while [`JsonKnownNamingPolicy`](xref:System.Text.Json.JsonKnownNamingPolicy)remains available for compile-time naming options.
52
52
53
53
> [!NOTE]
54
54
> This allows you to share model classes between JSON and TOML serializers. TOML-specific attributes take precedence when both are present.
Copy file name to clipboardExpand all lines: site/docs/source-generation.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,10 +18,9 @@ It follows the same patterns as [`System.Text.Json`](xref:System.Text.Json) sour
18
18
19
19
## Define a context
20
20
21
-
Declare a `partial` class that inherits from [`TomlSerializerContext`](xref:Tomlyn.Serialization.TomlSerializerContext) and annotate it with [`[JsonSerializable]`](xref:System.Text.Json.Serialization.JsonSerializableAttribute) for each root type:
21
+
Declare a `partial` class that inherits from [`TomlSerializerContext`](xref:Tomlyn.Serialization.TomlSerializerContext) and annotate it with [`[TomlSerializable]`](xref:Tomlyn.Serialization.TomlSerializableAttribute) for each root type:
22
22
23
23
```csharp
24
-
usingSystem.Text.Json.Serialization;
25
24
usingTomlyn.Serialization;
26
25
27
26
publicsealedclassServerConfig
@@ -30,12 +29,13 @@ public sealed class ServerConfig
The generator produces a `Default` singleton and a typed [`TomlTypeInfo<T>`](xref:Tomlyn.TomlTypeInfo`1) property for each root.
38
37
Nested types referenced by the root are discovered transitively - you only need to annotate top-level types.
38
+
Set [`TomlSerializableAttribute.TypeInfoPropertyName`](xref:Tomlyn.Serialization.TomlSerializableAttribute.TypeInfoPropertyName) when you want to customize the generated property name exposed by the context.
| Generated properties are missing | Ensure the project references the `Tomlyn` NuGet package (the generator is shipped under `analyzers/dotnet/cs`). |
155
155
| Compilation errors on context | Ensure the context class is `partial`. |
156
-
| Type not found on context | Ensure root types are declared via `[JsonSerializable(typeof(...))]`. |
156
+
| Type not found on context | Ensure root types are declared via `[TomlSerializable(typeof(...))]`. |
157
157
| Nested types not serialized | Nested types are discovered transitively - verify they're reachable from a root type. |
158
158
| Converter not applied | Use `TomlSourceGenerationOptionsAttribute.Converters` instead of `TomlConverterAttribute` for source-generated contexts. |
0 commit comments