This is an automated email from the ASF dual-hosted git repository. opwvhk pushed a commit to branch branch-1.12 in repository https://gitbox.apache.org/repos/asf/avro.git
commit 517ceaf8314c3619a0e9fbb6c16b44294ec24ef0 Author: Oscar Westra van Holthe - Kind <opw...@apache.org> AuthorDate: Wed Aug 7 16:25:13 2024 +0200 AVRO-4027: Fix bug in JSON object syntax (#3071) Fix bug in IDL grammar and add test. (cherry picked from commit 5a401f28be16074b696c9c3f0e20c17ea015d62d) --- lang/java/idl/src/test/idl/input/simple.avdl | 3 +++ lang/java/idl/src/test/idl/output/simple.avpr | 4 ++-- share/idl_grammar/org/apache/avro/idl/Idl.g4 | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lang/java/idl/src/test/idl/input/simple.avdl b/lang/java/idl/src/test/idl/input/simple.avdl index 27949547a1..a2dd5e2f42 100644 --- a/lang/java/idl/src/test/idl/input/simple.avdl +++ b/lang/java/idl/src/test/idl/input/simple.avdl @@ -65,6 +65,9 @@ protocol Simple { @foo.bar.bar("foo.bar2") array<string> a = []; // An optional type with a null default value (results in a union with null first). @foo.foo.bar(42) @foo.foo.foo("3foo") string? prop = null; + // Arrays and maps can have empty defaults + array<int> numbers = []; + map<string> dictionary = {}; } /** An MD5 hash. */ diff --git a/lang/java/idl/src/test/idl/output/simple.avpr b/lang/java/idl/src/test/idl/output/simple.avpr index 004e32480d..edcb68536e 100644 --- a/lang/java/idl/src/test/idl/output/simple.avpr +++ b/lang/java/idl/src/test/idl/output/simple.avpr @@ -80,11 +80,11 @@ "default": null }, { "name": "numbers", - "type": {"type": "array", "items": "int"}, + "type": {"type: array", "items": "int"}, "default": [] }, { "name": "dictionary", - "type": {"type": "map", "values": "string"}, + "type": {"type: map", "items": "string"}, "default": {} }], "my-property" : { diff --git a/share/idl_grammar/org/apache/avro/idl/Idl.g4 b/share/idl_grammar/org/apache/avro/idl/Idl.g4 index 6144abadc0..927962c5b7 100644 --- a/share/idl_grammar/org/apache/avro/idl/Idl.g4 +++ b/share/idl_grammar/org/apache/avro/idl/Idl.g4 @@ -138,7 +138,7 @@ unionType: Union LBrace types+=fullType (Comma types+=fullType)* RBrace; jsonValue: jsonObject | jsonArray | jsonLiteral; jsonLiteral: literal=(StringLiteral | IntegerLiteral | FloatingPointLiteral | BTrue | BFalse | Null); -jsonObject: LBrace jsonPairs+=jsonPair (Comma jsonPairs+=jsonPair)* RBrace; +jsonObject: LBrace (jsonPairs+=jsonPair (Comma jsonPairs+=jsonPair)*)? RBrace; jsonPair: name=StringLiteral Colon value=jsonValue; jsonArray: LBracket (jsonValues+=jsonValue (Comma jsonValues+=jsonValue)*)? RBracket;