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

[Internal] JsonObjectState: Refactors to allow dynamically increasing JsonMaxNestingDepth #4542

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sc978345
Copy link
Contributor

Description

This PR modifies Json object state to support dynamically increasing the maximum nesting depth. This will allow serialization/deserialization of Json with deeply nested objects or arrays. This is needed because distribution plans may contain expressions that are deeply nested beyond the current limit.

Previously, there was a hardcoded limit of 256 for JsonMaxNestingDepth. With this change, if the limit is reached, JsonObjectState will dynamically increase the value until the supported limit of 2^15 (32k) is reached

Type of change

  • [] Bug fix (non-breaking change which fixes an issue)

…mum nesting depth. This will allow serialization/deserialization of Json with deeply nested objects or arrays. This is needed because distribution plans may contain expressions that are deeply nested beyond the current limit.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

All good!

@sc978345 sc978345 changed the title [Internal] Allow JsonObjectState to dynamically increase JsonMaxNestingDepth [Internal] JsonObjectState: Refactors to allow dynamically increasing JsonMaxNestingDepth Jun 11, 2024
Debug.Assert(this.jsonMaxNestingDepth < (1 << 15), "JsonMaxNestingDepth must be less than 2^15");

byte[] newNestingStackBitmap = new byte[newJsonMaxNestingDepth / 8];
Array.Copy(this.nestingStackBitmap, newNestingStackBitmap, Math.Min(this.nestingStackBitmap.Length, newNestingStackBitmap.Length));
Copy link
Contributor

Choose a reason for hiding this comment

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

Please consider using Array.Resize

@@ -168,5 +168,35 @@ public void TestUnknownStruct()
DateTime value = DateTime.MinValue;
ReadOnlyMemory<byte> result = JsonSerializer.Serialize(value);
}

[TestMethod]
public void TestMaxNestingDepethResize()
Copy link
Contributor

Choose a reason for hiding this comment

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

TestMaxNestingDepethResize

[Nit] Typo

@sc978345 sc978345 marked this pull request as draft June 14, 2024 14:38
@kirankumarkolli
Copy link
Member

@sc978345 can you please take a look at the comments and address them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants