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

Add JsonContent.Create overloads which accept JsonTypeInfo #89614

Merged
merged 6 commits into from
Jul 31, 2023

Conversation

brantburnett
Copy link
Contributor

This adds JsonContent.Create overloads that accept JsonTypeInfo parameters as approved in #51544.

namespace System.Net.Http.Json
{
    public partial class JsonContent
    {
        public static JsonContent Create<TValue>(TValue? inputValue, JsonTypeInfo<TValue> jsonTypeInfo, MediaTypeHeaderValue? mediaType = null);
        public static JsonContent Create(object? inputValue, JsonTypeInfo jsonTypeInfo, MediaTypeHeaderValue? mediaType = null);
    }
}

I did consider changing the internal JsonContent<T> overload to inherit from JsonContent. However, this requires unsealing JsonContent which was not approved. More importantly, to work well ObjectType and especially Value would need to be made virtual, which is not an allowed change to the API surface due to binary compatibility requirements. This approach seemed cleaner at the cost of a very lightweight additional abstraction layer.

Fixes #51544

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 28, 2023
@ghost
Copy link

ghost commented Jul 28, 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

This adds JsonContent.Create overloads that accept JsonTypeInfo parameters as approved in #51544.

namespace System.Net.Http.Json
{
    public partial class JsonContent
    {
        public static JsonContent Create<TValue>(TValue? inputValue, JsonTypeInfo<TValue> jsonTypeInfo, MediaTypeHeaderValue? mediaType = null);
        public static JsonContent Create(object? inputValue, JsonTypeInfo jsonTypeInfo, MediaTypeHeaderValue? mediaType = null);
    }
}

I did consider changing the internal JsonContent<T> overload to inherit from JsonContent. However, this requires unsealing JsonContent which was not approved. More importantly, to work well ObjectType and especially Value would need to be made virtual, which is not an allowed change to the API surface due to binary compatibility requirements. This approach seemed cleaner at the cost of a very lightweight additional abstraction layer.

Fixes #51544

Author: brantburnett
Assignees: -
Labels:

area-System.Text.Json, new-api-needs-documentation

Milestone: -

…onContent.cs

Co-authored-by: Eirik Tsarpalis <eirik.tsarpalis@gmail.com>
Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, and for simplifying the implementation :-)

@brantburnett
Copy link
Contributor Author

Thank you for your contribution, and for simplifying the implementation :-)

Thanks for teaching me the new JsonTypeInfo tricks. :)

@eiriktsarpalis eiriktsarpalis added this to the 8.0.0 milestone Jul 31, 2023
@eiriktsarpalis eiriktsarpalis merged commit 7e2eb6b into dotnet:main Jul 31, 2023
103 checks passed
@brantburnett brantburnett deleted the jsoncontent-jsontypeinfo branch July 31, 2023 16:24
@ghost ghost locked as resolved and limited conversation to collaborators Aug 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add JsonContent.Create overloads that accept JsonTypeInfo.
2 participants