tradercentric commented on code in PR #2519:
URL: https://github.com/apache/avro/pull/2519#discussion_r1336121049
##########
lang/csharp/src/apache/main/Schema/Schema.cs:
##########
@@ -243,11 +244,28 @@ internal static Schema Parse(string json, SchemaNames
names, string encspace)
Schema sc = PrimitiveSchema.NewInstance(json);
if (null != sc) return sc;
+ // Refer to https://issues.apache.org/jira/browse/AVRO-3856
+ // Refer to https://github.com/JamesNK/Newtonsoft.Json/pull/2904
+ // Newtonsoft author advised to use JObject.Load/JArray.Load
instead of JObject.Parse()/JArray.Parse()
+ // The reason is we can set the MaxDepth property on the
JsonReader.
+ JsonReader reader = new JsonTextReader(new StringReader(json));
+ // Another issue discovered is JsonReader.Push(JsonContainerType
value) method overcounting the depth
+ // level of Avro schema. Here are the observation of
over-counting depth level in Newtonsoft's JsonReader:
+ // Avro Schema Depth JsonReader Depth Level Count
+ // 4 11
+ // 16 44
+ // 32 92
+ // 64 188
+ // So, roughly speaking, the depth level count is about 2.75 times
of Avro schema depth.
+ // Below is the hard-coded value to compensate over-counting of
depth level in Newtonsoft
+ // to support Avro schema depth level to 64 slightly beyond.
+ reader.MaxDepth = 192;
+
try
{
bool IsArray = json.StartsWith("[", StringComparison.Ordinal)
&& json.EndsWith("]", StringComparison.Ordinal);
- JContainer j = IsArray ? (JContainer)JArray.Parse(json) :
(JContainer)JObject.Parse(json);
+ JContainer j = IsArray ? (JContainer)JArray.Load(reader) :
(JContainer)JObject.Load(reader);
Review Comment:
Ack. In progress to look into it
##########
lang/csharp/src/apache/main/Schema/Schema.cs:
##########
@@ -243,11 +244,28 @@ internal static Schema Parse(string json, SchemaNames
names, string encspace)
Schema sc = PrimitiveSchema.NewInstance(json);
if (null != sc) return sc;
+ // Refer to https://issues.apache.org/jira/browse/AVRO-3856
+ // Refer to https://github.com/JamesNK/Newtonsoft.Json/pull/2904
+ // Newtonsoft author advised to use JObject.Load/JArray.Load
instead of JObject.Parse()/JArray.Parse()
+ // The reason is we can set the MaxDepth property on the
JsonReader.
+ JsonReader reader = new JsonTextReader(new StringReader(json));
Review Comment:
Ack. In progress to look into it
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]