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 WriteTo convenience APIs on JsonDocument and JsonProperty #30084
Comments
@ahsonkhan Hi, I would like to contribute. Do you think its good issue to get started? Since it marked as "api-ready-for-review", I need to wait till API getting approved before working on it, right? |
@sasivishnu This issue isn't ready yet. @ahsonkhan I don't think we should mark API suggestions that weren't approved as up-for-grabs. /cc @karelz |
Removing up-for-grabs until the API change has been approved. |
Can we instead add Write methods to |
We liked option Part A) + Part B) 2, i.e. a single
We don't want this for layering reasons, i.e. the DOM knows about the writer, but the writer shouldn't know about the DOM. |
@terrajobst I was listening to Design Review video. One thing I can't able to catch clear is "Are we going to remove all existing Btw, is this now "up for grabs" since API is approved? |
@sasivishnu Yes, we're removing JsonElement.WriteProperty (all overloads) and renaming JsonElement.WriteValue. Consider the issue yours (though be advised the PR can't be merged until we work out some "late breaking change" paperwork on our side...) |
@ahsonkhan @bartonjs
|
A couple of additions / clarifications 1.5) Add |
@bartonjs Thanks. Couple of clarifications on testing,
|
I would say, yes, do 1a). I don't see any harm in keeping existing tests which cover more of utf8jsonwriter/jsonelement interop scenarios. For 2, I prefer a new file, but will defer to @bartonjs |
Hm, apparently I have this half filled out on a different computer.
My original answer was "delete them". but then I was going to say a nuanced thing that I think is so nuanced that I can't explain it (of trying to ensure the scenario coverage). So just changing them to be writer.WritePropertyName and element.WriteTo is the easiest answer.
For JsonElement the write tests are in Existing JsonProperty tests are just in JsonDocumentTests (because there weren't many of them). Having looked at JsonDocumentTests again just now, I think that
|
Thanks. I will get PR ready by next week (traveling till next Wednesday). |
* Remove WriteProperty methods and rename WriteValue to WriteTo in JsonElement (#39037) * Add WriteTo method in JsonDocument and JsonProperty (#39037) * Remove all repeated tests from JsonDocument and JsonProperty for now. * Added null check for Utf8JsonWriter parameter in WriteTo methods on JsonElement, JsonDocument and JsonProperty * Code review changes
Based on the usability study feedback, we realized that having convenience "write" APIs on JsonDocument and JsonProperty would be quite useful for users, especially for discovery.
People expect a Write method on the document itself and having to write the root element feels odd.
We should also align JsonProperty with JsonElement and add Write method that takes a writer to JsonProperty.
Current APIs on
JsonElement
:Proposal:
Part A) Add write APIs to
JsonDocument
andJsonProperty
:Part B) Optionally, update the APIs on JsonElement for consistency
Sample Usage:
Before:
After:
Questions:
WriteProperty
APIs onJsonElement
and renameWriteValue
to beWriteTo
? That is the most consistent/cleanest API shape (both internally with JsonDocument, JsonProperty, etc., and externally with Newtonsoft Json's JToken, and Xml APIs).WriteProperty
APIs onJsonElement
, should we re-order the parameters so that the writer comes up first?Sample implementation:
dotnet/corefx@78615e1
cc @bartonjs, @terrajobst, @steveharter, @JeremyKuhne
The text was updated successfully, but these errors were encountered: