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

[API Proposal]: Add freezing APIs to JsonTypeInfo #76893

Closed
eiriktsarpalis opened this issue Oct 11, 2022 · 2 comments · Fixed by #76540
Closed

[API Proposal]: Add freezing APIs to JsonTypeInfo #76893

eiriktsarpalis opened this issue Oct 11, 2022 · 2 comments · Fixed by #76540
Assignees
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Text.Json
Milestone

Comments

@eiriktsarpalis
Copy link
Member

eiriktsarpalis commented Oct 11, 2022

Background and motivation

Following up on #76540, this tracks the proposal to add user browsable locking APIs for the System.Text.Json metadata types. It follows the API shape applied to JsonSerializerOptions in #74431.

API Proposal

namespace System.Text.Json.Metadata;

public partial static class JsonTypeInfo
{
    public bool IsReadOnly { get; }
    public void MakeReadOnly();
}

API Usage

var resolver = new DefaultJsonTypeInfoResolver
{
    Modifiers =
    {
         static typeInfo =>
         {
               if (typeInfo.IsReadOnly)
               {
                       // type is locked for further modification, exit the modifier
                       return;
               }

               if (typeInfo.Type == typeof(MySpecialPoco))
               {
                      typeInfo.CreateObject = () => new MySpecialPoco("defaultValue");
                      // prevent subsequent modifiers/resolvers from further modifying this contract
                      typeInfo.MakeReadOnly(); 
               }
         }
    }
};

Alternative Designs

No response

Risks

No response

@eiriktsarpalis eiriktsarpalis added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Oct 11, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@eiriktsarpalis eiriktsarpalis added api-ready-for-review API is ready for review, it is NOT ready for implementation and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation labels Oct 11, 2022
@eiriktsarpalis eiriktsarpalis self-assigned this Oct 11, 2022
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 11, 2022
@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone Oct 11, 2022
@eiriktsarpalis eiriktsarpalis added area-System.Text.Json and removed untriaged New issue has not been triaged by the area owner labels Oct 11, 2022
@ghost
Copy link

ghost commented Oct 11, 2022

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

Background and motivation

Following up on #76540, this tracks the proposal to add user browsable locking APIs for the System.Text.Json metadata types. It follows the API shape applied to JsonSerializerOptions in #74431.

API Proposal

namespace System.Text.Json.Metadata;

public partial static class JsonTypeInfo
{
    public bool IsReadOnly { get; }
    public void MakeReadOnly();
}

API Usage

var resolver = new DefaultJsonTypeInfoResolver
{
    Modifiers =
    {
         static typeInfo =>
         {
               if (typeInfo.IsReadOnly)
               {
                       // type is locked for further modification, exit the modifier
                       return;
               }

               if (typeInfo.Type == typeof(MySpecialPoco))
               {
                      typeInfo.CreateObject = () => new MySpecialPoco("defaultValue");
                      // prevent subsequent modifiers/resolvers from further modifying this contract
                      typeInfo.MakeReadOnly(); 
               }
         }
    }
}

Alternative Designs

No response

Risks

No response

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Text.Json, api-ready-for-review

Milestone: 8.0.0

@eiriktsarpalis eiriktsarpalis added the in-pr There is an active PR which will close this issue when it is merged label Oct 12, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Oct 12, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Text.Json
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant