Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add WritePropertyName standlone API on the Utf8JsonWriter. #38864

Merged
5 commits merged into from
Jun 25, 2019

Conversation

@ahsonkhan ahsonkhan added this to the 3.0 milestone Jun 25, 2019
@ahsonkhan ahsonkhan self-assigned this Jun 25, 2019
/// The property name should already be escaped when the instance of <see cref="JsonEncodedText"/> was created.
/// </remarks>
/// <exception cref="InvalidOperationException">
/// Thrown if this would result in an invalid JSON to be written (while validation is enabled).
Copy link
Member

Choose a reason for hiding this comment

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

"would result in an invalid JSON to be written" is strange grammatically. How about "would result in invalid JSON being written"?

/// <param name="propertyName">The JSON encoded property name of the JSON object to be transcoded and written as UTF-8.</param>
/// </summary>
/// <remarks>
/// The property name should already be escaped when the instance of <see cref="JsonEncodedText"/> was created.
Copy link
Member

@stephentoub stephentoub Jun 25, 2019

Choose a reason for hiding this comment

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

"The property name should already be escaped when the instance of JsonEncodedText was created." is strange . What is it trying to convey? Is there something the user needed to do but didn't? Is this stating a fact about something that must be the case?

Copy link
Member

Choose a reason for hiding this comment

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

I agree this remark is weird. It's like taking an int and remarking the value has to be between int.MinValue and int.MaxValue inclusive... it's a truth provided by the type system.

}
else
{
// Cannot create a span directly since it gets assigned to parameter and passed down.
Copy link
Member

Choose a reason for hiding this comment

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

Are we not able to work around this now with readonly members?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy-pasted from existing code, so will have to fix this across the board. Out-of-scope for this PR.


Span<byte> output = _memory.Span;

if (_currentDepth < 0)
Copy link
Member

Choose a reason for hiding this comment

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

I had to go find the comment on _currentDepth to understand how a depth could be negative. Consider instead creating a private property that does this check and is appropriately named to describe what it's actually checking.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy-pasted from existing code, so will have to fix this across the board. Out-of-scope for this PR.

/// <summary>
/// Writes the property name (as a JSON string) as the first part of a name/value pair of a JSON object.
/// </summary>
/// <param name="propertyName">The property name of the JSON object to be transcoded and written as UTF-8.</param>
Copy link
Member

Choose a reason for hiding this comment

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

transcoded and written as UTF-8

Does it really make sense to mention this detail everywhere?

@@ -9,6 +9,353 @@ namespace System.Text.Json
{
public sealed partial class Utf8JsonWriter
{
/// <summary>
/// Writes the pre-encoded property name (as a JSON string) as the first part of a name/value pair of a JSON object.
/// <param name="propertyName">The JSON encoded property name of the JSON object to be transcoded and written as UTF-8.</param>
Copy link
Member

@bartonjs bartonjs Jun 25, 2019

Choose a reason for hiding this comment

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

Who said anything about transcoding? That's an irrelevant implementation detail (if the JsonEncodedText doesn't pre-transcode, then the only way to avoid transcoding is to use the ROS-byte overload... which runs the escaper. So it's not worth mentioning, especially in the param tag... remarks if you must.)

Suggested change
/// <param name="propertyName">The JSON encoded property name of the JSON object to be transcoded and written as UTF-8.</param>
/// <param name="propertyName">The name of the property to write.</param>

@ahsonkhan
Copy link
Member Author

ahsonkhan commented Jun 25, 2019

A lot of the feedback here was around comments/documentation re-wording which was primarily copy-pasted from existing APIs. I am going to defer addressing that feedback to scope this PR down to what is relevant just to this change and do a larger comments re-wording in the future, especially given the time constraint (and to ublock other work around converters - cc @steveharter).

Appreciate the input.

https://github.com/dotnet/corefx/issues/38896

@ahsonkhan ahsonkhan added the auto-merge Automatically merge PR once CI passes. label Jun 25, 2019
@ghost
Copy link

ghost commented Jun 25, 2019

Hello @ahsonkhan!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@bartonjs bartonjs removed the auto-merge Automatically merge PR once CI passes. label Jun 25, 2019
Copy link
Member

@bartonjs bartonjs left a comment

Choose a reason for hiding this comment

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

Waiting on tests to show that WriteBoolean(propertyName, value) and friends are not valid (when validation is not suppressed) after WritePropertyName

@ahsonkhan
Copy link
Member Author

ahsonkhan commented Jun 25, 2019

Waiting on tests to show that WriteBoolean(propertyName, value) and friends are not valid (when validation is not suppressed) after WritePropertyName

Up-stack consumers are waiting on this change and this PR is blocking some of the converter work. I would like to get this in and will address adding more tests for those cases separately. I do have very similar tests for other "WriteX(propertyName, value)", but not for all TokenTypes, so I am fairly confident this works as expected.

I would like to avoid resetting CI at this point.

@ahsonkhan ahsonkhan added the auto-merge Automatically merge PR once CI passes. label Jun 25, 2019
@ghost ghost merged commit a5b35f5 into dotnet:master Jun 25, 2019
@ahsonkhan ahsonkhan deleted the WritePropertyName branch June 26, 2019 00:38
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…refx#38864)

* Add WritePropertyName standlone API on the Utf8JsonWriter.

* Fix write indented, add more tests, and more debug.asserts.

* Remove _isProperty field and rely on _tokenType ==
JsonTokenType.PropertyName

* Auto-gen the ref.

* Address PR feedback.


Commit migrated from dotnet/corefx@a5b35f5
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Text.Json auto-merge Automatically merge PR once CI passes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for custom converters and OnXXX callbacks
4 participants