Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a number of improvements to the System.Text.Json source generator #81239

Merged
merged 6 commits into from
Jan 27, 2023

Conversation

eiriktsarpalis
Copy link
Member

Makes a number of improvements to the System.Text.Json source generator:

  1. Ensures that the source generated JsonTypeInfo<T> singleton instances are populated via the corresponding JsonSerializerOptions cache and are thus preconfigured before they are surfaced to users. The generated metadata properties now look as follows:
     internal partial class ClassWithStringValuesContext
     {
         private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.String>? _String;
             
         /// <summary>
         /// Defines the source generated JSON serialization contract metadata for a given type.
         /// </summary>
         public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.String> String
         {
             get => _String ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.String>)Options.GetTypeInfo(typeof(global::System.String));
         }
     }
  2. Fixes indentation & whitespace issues with generated source code, particularly with contexts not in namespaces.
  3. Fix JSON source generator emits CS0612 warnings if serialized types use [Obsolete] #76829.

I've split the relevant changes into separate commits for easier reviewing.

@ghost
Copy link

ghost commented Jan 26, 2023

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

Makes a number of improvements to the System.Text.Json source generator:

  1. Ensures that the source generated JsonTypeInfo<T> singleton instances are populated via the corresponding JsonSerializerOptions cache and are thus preconfigured before they are surfaced to users. The generated metadata properties now look as follows:
     internal partial class ClassWithStringValuesContext
     {
         private global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.String>? _String;
             
         /// <summary>
         /// Defines the source generated JSON serialization contract metadata for a given type.
         /// </summary>
         public global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.String> String
         {
             get => _String ??= (global::System.Text.Json.Serialization.Metadata.JsonTypeInfo<global::System.String>)Options.GetTypeInfo(typeof(global::System.String));
         }
     }
  2. Fixes indentation & whitespace issues with generated source code, particularly with contexts not in namespaces.
  3. Fix JSON source generator emits CS0612 warnings if serialized types use [Obsolete] #76829.

I've split the relevant changes into separate commits for easier reviewing.

Author: eiriktsarpalis
Assignees: -
Labels:

area-System.Text.Json

Milestone: -

@ghost ghost locked as resolved and limited conversation to collaborators Feb 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON source generator emits CS0612 warnings if serialized types use [Obsolete]
3 participants