[ 
https://issues.apache.org/jira/browse/AVRO-3001?focusedWorklogId=804723&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-804723
 ]

ASF GitHub Bot logged work on AVRO-3001:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 30/Aug/22 08:50
            Start Date: 30/Aug/22 08:50
    Worklog Time Spent: 10m 
      Work Description: martin-g commented on code in PR #1833:
URL: https://github.com/apache/avro/pull/1833#discussion_r958196081


##########
lang/csharp/src/apache/test/IO/JsonCodecTests.cs:
##########
@@ -0,0 +1,329 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using NUnit.Framework;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Avro.Generic;
+using Avro.IO;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace Avro.Test
+{
+    using Decoder = Avro.IO.Decoder;
+    using Encoder = Avro.IO.Encoder;
+
+    /// <summary>
+    /// Tests the JsonEncoder and JsonDecoder.
+    /// </summary>
+    [TestFixture]
+    public class JsonCodecTests
+    {
+        [TestCase("{ \"type\": \"record\", \"name\": \"r\", \"fields\": [ " +
+                  " { \"name\" : \"f1\", \"type\": \"int\" }, " +
+                  " { \"name\" : \"f2\", \"type\": \"float\" } " +
+                  "] }",
+            "{ \"f2\": 10.4, \"f1\": 10 } ")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", " \"s1\" ")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", " \"s2\" ")]
+        [TestCase("{ \"type\": \"fixed\", \"name\": \"f\", \"size\": 5 }", 
"\"hello\"")]
+        [TestCase("{ \"type\": \"array\", \"items\": \"int\" }", "[ 10, 20, 30 
]")]
+        [TestCase("{ \"type\": \"map\", \"values\": \"int\" }", "{ \"k1\": 10, 
\"k2\": 20, \"k3\": 30 }")]
+        [TestCase("[ \"int\", \"long\" ]", "{ \"int\": 10 }")]
+        [TestCase("\"string\"", "\"hello\"")]
+        [TestCase("\"bytes\"", "\"hello\"")]
+        [TestCase("\"int\"", "10")]
+        [TestCase("\"long\"", "10")]
+        [TestCase("\"float\"", "10.0")]
+        [TestCase("\"double\"", "10.0")]
+        [TestCase("\"boolean\"", "true")]
+        [TestCase("\"boolean\"", "false")]
+        [TestCase("\"null\"", "null")]
+        public void TestJsonAllTypesValidValues(String schemaStr, String value)
+        {
+            Schema schema = Schema.Parse(schemaStr);
+            byte[] avroBytes = fromJsonToAvro(value, schema);
+
+            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(value),
+                JToken.Parse(fromAvroToJson(avroBytes, schema, true))));
+        }
+
+        [TestCase("{ \"type\": \"record\", \"name\": \"r\", \"fields\": [ " +
+                  " { \"name\" : \"f1\", \"type\": \"int\" }, " +
+                  " { \"name\" : \"f2\", \"type\": \"float\" } " +
+                  "] }",
+            "{ \"f4\": 10.4, \"f3\": 10 } ")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", " \"s3\" ")]

Review Comment:
   ```suggestion
           [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": [ 
\"s1\", \"s2\"] }", " \"s3\" ")]
   ```



##########
lang/csharp/src/apache/test/IO/JsonCodecTests.cs:
##########
@@ -0,0 +1,329 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using NUnit.Framework;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Avro.Generic;
+using Avro.IO;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace Avro.Test
+{
+    using Decoder = Avro.IO.Decoder;
+    using Encoder = Avro.IO.Encoder;
+
+    /// <summary>
+    /// Tests the JsonEncoder and JsonDecoder.
+    /// </summary>
+    [TestFixture]
+    public class JsonCodecTests
+    {
+        [TestCase("{ \"type\": \"record\", \"name\": \"r\", \"fields\": [ " +
+                  " { \"name\" : \"f1\", \"type\": \"int\" }, " +
+                  " { \"name\" : \"f2\", \"type\": \"float\" } " +
+                  "] }",
+            "{ \"f2\": 10.4, \"f1\": 10 } ")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", " \"s1\" ")]

Review Comment:
   ```suggestion
           [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": [ 
\"s1\", \"s2\"] }", " \"s1\" ")]
   ```



##########
lang/csharp/src/apache/test/IO/JsonCodecTests.cs:
##########
@@ -0,0 +1,329 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using NUnit.Framework;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Avro.Generic;
+using Avro.IO;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace Avro.Test
+{
+    using Decoder = Avro.IO.Decoder;
+    using Encoder = Avro.IO.Encoder;
+
+    /// <summary>
+    /// Tests the JsonEncoder and JsonDecoder.
+    /// </summary>
+    [TestFixture]
+    public class JsonCodecTests
+    {
+        [TestCase("{ \"type\": \"record\", \"name\": \"r\", \"fields\": [ " +
+                  " { \"name\" : \"f1\", \"type\": \"int\" }, " +
+                  " { \"name\" : \"f2\", \"type\": \"float\" } " +
+                  "] }",
+            "{ \"f2\": 10.4, \"f1\": 10 } ")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", " \"s1\" ")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", " \"s2\" ")]
+        [TestCase("{ \"type\": \"fixed\", \"name\": \"f\", \"size\": 5 }", 
"\"hello\"")]
+        [TestCase("{ \"type\": \"array\", \"items\": \"int\" }", "[ 10, 20, 30 
]")]
+        [TestCase("{ \"type\": \"map\", \"values\": \"int\" }", "{ \"k1\": 10, 
\"k2\": 20, \"k3\": 30 }")]
+        [TestCase("[ \"int\", \"long\" ]", "{ \"int\": 10 }")]
+        [TestCase("\"string\"", "\"hello\"")]
+        [TestCase("\"bytes\"", "\"hello\"")]
+        [TestCase("\"int\"", "10")]
+        [TestCase("\"long\"", "10")]
+        [TestCase("\"float\"", "10.0")]
+        [TestCase("\"double\"", "10.0")]
+        [TestCase("\"boolean\"", "true")]
+        [TestCase("\"boolean\"", "false")]
+        [TestCase("\"null\"", "null")]
+        public void TestJsonAllTypesValidValues(String schemaStr, String value)
+        {
+            Schema schema = Schema.Parse(schemaStr);
+            byte[] avroBytes = fromJsonToAvro(value, schema);
+
+            Assert.IsTrue(JToken.DeepEquals(JToken.Parse(value),
+                JToken.Parse(fromAvroToJson(avroBytes, schema, true))));
+        }
+
+        [TestCase("{ \"type\": \"record\", \"name\": \"r\", \"fields\": [ " +
+                  " { \"name\" : \"f1\", \"type\": \"int\" }, " +
+                  " { \"name\" : \"f2\", \"type\": \"float\" } " +
+                  "] }",
+            "{ \"f4\": 10.4, \"f3\": 10 } ")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", " \"s3\" ")]
+        [TestCase("{ \"type\": \"fixed\", \"name\": \"f\", \"size\": 10 }", 
"\"hello\"")]
+        [TestCase("{ \"type\": \"array\", \"items\": \"int\" }", "[ \"10\", 
\"20\", \"30\" ]")]
+        [TestCase("{ \"type\": \"map\", \"values\": \"int\" }", "{ \"k1\": 
\"10\", \"k2\": \"20\"}")]
+        [TestCase("[ \"int\", \"long\" ]", "10")]
+        [TestCase("\"string\"", "10")]
+        [TestCase("\"bytes\"", "10")]
+        [TestCase("\"int\"", "\"hi\"")]
+        [TestCase("\"long\"", "\"hi\"")]
+        [TestCase("\"float\"", "\"hi\"")]
+        [TestCase("\"double\"", "\"hi\"")]
+        [TestCase("\"boolean\"", "\"hi\"")]
+        [TestCase("\"boolean\"", "\"hi\"")]
+        [TestCase("\"null\"", "\"hi\"")]
+        public void TestJsonAllTypesInvalidValues(String schemaStr, String 
value)
+        {
+            Schema schema = Schema.Parse(schemaStr);
+            Assert.Throws<AvroTypeException>(() => fromJsonToAvro(value, 
schema));
+        }
+
+        [TestCase("{ \"type\": \"record\", \"name\": \"r\", \"fields\": [ " +
+                  " { \"name\" : \"f1\", \"type\": \"int\" }, " +
+                  " { \"name\" : \"f2\", \"type\": \"float\" } " +
+                  "] }",
+            "{ \"f2\": 10.4, \"f1")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", "s1")]

Review Comment:
   ```suggestion
           [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": [ 
\"s1\", \"s2\"] }", "s1")]
   ```



##########
lang/csharp/src/apache/test/IO/JsonCodecTests.cs:
##########
@@ -0,0 +1,329 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+using System;
+using NUnit.Framework;
+using System.IO;
+using System.Linq;
+using System.Text;
+using Avro.Generic;
+using Avro.IO;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+
+namespace Avro.Test
+{
+    using Decoder = Avro.IO.Decoder;
+    using Encoder = Avro.IO.Encoder;
+
+    /// <summary>
+    /// Tests the JsonEncoder and JsonDecoder.
+    /// </summary>
+    [TestFixture]
+    public class JsonCodecTests
+    {
+        [TestCase("{ \"type\": \"record\", \"name\": \"r\", \"fields\": [ " +
+                  " { \"name\" : \"f1\", \"type\": \"int\" }, " +
+                  " { \"name\" : \"f2\", \"type\": \"float\" } " +
+                  "] }",
+            "{ \"f2\": 10.4, \"f1\": 10 } ")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", " \"s1\" ")]
+        [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": " + "[ 
\"s1\", \"s2\"] }", " \"s2\" ")]

Review Comment:
   ```suggestion
           [TestCase("{ \"type\": \"enum\", \"name\": \"e\", \"symbols\": [ 
\"s1\", \"s2\"] }", " \"s2\" ")]
   ```





Issue Time Tracking
-------------------

    Worklog Id:     (was: 804723)
    Time Spent: 10h 10m  (was: 10h)

> JsonEncode Decode support for C#
> --------------------------------
>
>                 Key: AVRO-3001
>                 URL: https://issues.apache.org/jira/browse/AVRO-3001
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: csharp
>    Affects Versions: 1.10.0, 1.11.0
>            Reporter: Krishnan Unni
>            Assignee: Robert Yokota
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.12.0
>
>          Time Spent: 10h 10m
>  Remaining Estimate: 0h
>
> The C# library for avro currently supports only the Binary encoding and also 
> with compile time types (Generic support only). As part of a project I am 
> doing I need to validate the avro schema against the incoming json data on 
> the fly without a predefined type (generated class). So basically comparing 
> an avro schema (string/json representation) against a raw json string. It is 
> possible with the Java library since it supports both non generic types and 
> streams as well as json encoding. With C# currently this is not possible. Is 
> there a plan to extend the C# library to provide these features? If yes, is 
> there a timeline? If not is there any alternative to achieve this? 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to