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

Please allow setting the max depth in JObject and JArray's Parse method #2900

Open
tradercentric opened this issue Sep 20, 2023 · 1 comment

Comments

@tradercentric
Copy link

tradercentric commented Sep 20, 2023

For Avro message deserialization, I am in need for Confluent to support parsing Avro schema that is more than 64 depth levels where Confluent library is using Newtonsoft library to parse into Avro schema object.

Currently, there is an issue logged with with Apache Avro where Confluent is not able parse Avro schema where the json is over 64 depth level.

The references to the issue are logged at

https://issues.apache.org/jira/browse/AVRO-3856
https://github.com/apache/avro/blob/41b3c08ca5da192786c2b08546e691b3126e1856/lang/csharp/src/apache/main/Schema/Schema.cs#L250

I think we would need the community help to add the feature to set the max depth for JObject and JArray Parse method. Here is what I am thinking if below updates are feasible.

In Newtonsoft.Json.Linq.JsonLoadSettings,

public int? MaxDepth { get; set; } // add

In Newtonsoft.Json.Linq.JObject

    public new static JObject Parse(string json, JsonLoadSettings? settings)
    {
        using (JsonReader reader = new JsonTextReader(new StringReader(json)))
        {
            var maxDepth = settings?.MaxDepth;         //add
            if (maxDepth != null)                                   //add
            {
                reader.MaxDepth = maxDepth;               //add
            }

In Newtonsoft.Json.Linq.JArray

    public new static JArray Parse(string json, JsonLoadSettings? settings)
    {
        using (JsonReader reader = new JsonTextReader(new StringReader(json)))
        {
            var maxDepth = settings?.MaxDepth;        //add
            if (maxDepth != null)                                  //add
            {
                reader.MaxDepth = maxDepth;             //add
            }

I attached a schame.txt which contain a json more than 64 depth level for replicate the issue.

schema.txt

P.S. I noticed Microsoft.Text.Json.Nodes support the passing of max depth, so I hope Newtonsoft can support the feature as well.

using System.Text.Json;
using System.Text.Json.Nodes;

var schema = File.ReadAllText("Schemas/schema.txt");

JsonDocumentOptions options = new()
{
MaxDepth = 128
};

JsonNode.Parse(schema, null, options);

@tradercentric
Copy link
Author

tradercentric commented Nov 29, 2023

First time I really tried to contribute to open source community by providing fixes but was getting nowhere with Newtonsoft, or Apache Avro. For the closing, our company architects approved the source team to use string for the value for XML format. To all who cares I wish you with good luck using deeply nested Avro schema.

Reference to: https://issues.apache.org/jira/browse/AVRO-3856

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

No branches or pull requests

1 participant