Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

JSON DOM refactor - #41041

Merged
ahsonkhan merged 13 commits into
dotnet:masterfrom
kasiabulat:kasiabulat/writable-json-dom-refactor
Nov 14, 2019
Merged

ahsonkhan merged 13 commits into
dotnet:masterfrom
kasiabulat:kasiabulat/writable-json-dom-refactor

Conversation

@kasiabulat

Copy link
Copy Markdown
Contributor

I addressed most review comments from #40673. I am left with changing throwing exceptions to using throwing exception helpers.

addresses: #39922
cc: @bartonjs @ahsonkhan @ericstj @joperezr @terrajobst @JamesNK @stephentoub

set
{
_list[idx] = value ?? new JsonNull();
_list[idx] = value ?? JsonNull.s_jsonNullInstance;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ahsonkhan is this right? I get we don't want to extra allocate when possible, but is there ever a case where introducing this into a tree might cause conflicts if you have the same instance more than once in a tree?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is really the open issue of "does JsonNode need the ability to move to Parent (or prev/next sibling)?" If no: Cache null/true/false. If yes: new instance every time.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One of the only issues that I could see is trying to serialize a jsonnode with duplicate references for nulls somehow creating cycles (or confusing the potential preserve-references feature). Otherwise, I don't see where the tree itself would care about duplicate references.

public void Add(JsonNode value)
{
_list.Add(value ?? new JsonNull());
_list.Add(value ?? JsonNull.s_jsonNullInstance);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we plan to do add any checks here and in JsonObject in case the JsonNode value was already part of the same tree which would cause cycles?

/// </summary>
public JsonNull() { }

internal static JsonNull s_jsonNullInstance = new JsonNull();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given that we are using now an instance in here, should we just move this type to use the singleton pattern instead so users don't allocate when not needed?

@bartonjs

Copy link
Copy Markdown
Member

I am left with changing throwing exceptions to using throwing exception helpers.

Our general stance is "write simple code, and use ThrowHelper when needed". Unless we expect these types to be bottlenecks for significant workloads it's not a desired change.

@kasiabulat

Copy link
Copy Markdown
Contributor Author

I think test failures are unrelated to my changes.

@ericstj

ericstj commented Sep 19, 2019

Copy link
Copy Markdown
Member

Are you sure? They are all failing in Json test. https://dev.azure.com/dnceng/public/_build/results?buildId=360129&view=ms.vss-test-web.build-test-results-tab&runId=10903936&resultId=153392&paneView=debug

Error message
Assert.True() Failure\nExpected: True\nActual: False

Stack trace
   at System.Text.Json.Tests.JsonObjectTests.TestChangingCurrentCulture() in /_/src/System.Text.Json/tests/JsonObjectTests.cs:line 855

[Fact]
public static void TestChangingCurrentCulture()
{
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like this test is failing on linux. Since you're modifying a static it may be a threading issue. You might want to make this a remote executor test. /cc @tarekgh

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, I misinterpreted logs tab information and assumed it should be OK, because I checked it on both architectures locally and in past got unrelated failures.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO don’t test current culture. It is simplest to test the difference between ordinal and ordinal ignorecase

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, sure. I can remove it for now and we can consider adding this back in future.

@kasiabulat

Copy link
Copy Markdown
Contributor Author

I think it's ready to be merged now. But probably some minor adjustments will need to be done when #41030 is merged.

@ahsonkhan ahsonkhan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Otherwise, LGTM.

@maryamariyan

maryamariyan commented Nov 6, 2019 •

Copy link
Copy Markdown

Thank you for your contribution. As announced in dotnet/coreclr#27549 this repository will be moving to dotnet/runtime on November 13. If you would like to continue working on this PR after this date, the easiest way to move the change to dotnet/runtime is:

  1. In your corefx repository clone, create patch by running git format-patch origin
  2. In your runtime repository clone, apply the patch by running git apply --directory src/libraries <path to the patch created in step 1>

@joperezr

Copy link
Copy Markdown
Member

cc @maryamariyan this change was actually supposed to be ported over by either @ahsonkhan or myself but we just haven't had any time to do it. @ahsonkhan and I will sync about this offline and will update the status of what will happen to this PR.

@maryamariyan

maryamariyan commented Nov 11, 2019 •

Copy link
Copy Markdown

@joperezr sounds good. If you believe that the PR is not planned for approval/merge until Nov 13, you can label it as post-consolidation.

@joperezr

Copy link
Copy Markdown
Member

I chatted with @ahsonkhan and looks like we will try to get this finished and in before Nov 13. If anything changes I'll let you know.

@ahsonkhan

ahsonkhan commented Nov 13, 2019 •

Copy link
Copy Markdown

This is ready to be reviewed/merged now. I kept the changes minimal, but I believe all existing feedback has been addressed. @bartonjs, @joperezr - can you take a quick look please?

@bartonjs bartonjs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't remember what the problems were to say if it solved them; but it seems to all be improvements.

@ahsonkhan

Copy link
Copy Markdown

@ahsonkhan
ahsonkhan merged commit a0f71fa into dotnet:master Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants