-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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]: Allow inheritance for Utf8JsonWriter class #111899
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
Changing non-virtual method to virtual is massive breaking change and can't happen. It also affects performance significantly. |
There's also lack of symmetry vis-a-vis |
@eiriktsarpalis @eiriktsarpalis Can we do something else to support customization of output JSON format? Without much overhead from a maintenance and performance perspective. I didn't know that changing non-virtual methods to virtual causes a breaking change even if the base class was sealed before. |
Depends on what you mean by customization. If you want to be able to customize the JSON produced for particular types then |
Basically I want to control the format of the output Json. Below is a simple example Input Json: {"a":1} |
It's unlikely we'd ever be able to support his given how STJ is currently designed. You might consider using the |
Background and motivation
Currently, Utf8JsonWriter is masked as
sealed
to prevent inheritance, which makes sense assealed
classes have slightly better performance but it prevents the users from customizing the output JSON format other than the options provided by theJsonWriterOptions
which is very limit and restrictive. For eg: it only allows specific char/string to be used for IndentCharacter and NewLine and doesn't allow customisation of many other things.A real-world use case for this request is for microsoft/garnet project, where we have to respond to the user in the format they specified in the input for the JSON module which is not supported in
Utf8JsonWriter
as of today. For this use case, there are only two options, either Garnet can never support the customizability provided by Redis for certain Json commands, or Garnet should use Newtonsoft.Json (which supports customisation). Both of these options are not ideal.API Proposal
API Usage
Alternative Designs
No response
Risks
We will lose the "slightly better performance" of
sealed
modifierThe text was updated successfully, but these errors were encountered: