Skip to content

Commit

Permalink
AVRO-4027: Fix bug in JSON object syntax (#3071)
Browse files Browse the repository at this point in the history
Fix bug in IDL grammar and add test.
  • Loading branch information
opwvhk authored Aug 7, 2024
1 parent 7a8ec75 commit 5a401f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lang/java/idl/src/test/idl/input/simple.avdl
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 8 additions & 0 deletions lang/java/idl/src/test/idl/output/simple.avpr
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
"name": "prop",
"type": [ "null" , {"type":"string", "foo.foo.bar": 42, "foo.foo.foo": "3foo"} ],
"default": null
}, {
"name": "numbers",
"type": {"type: array", "items": "int"},
"default": []
}, {
"name": "dictionary",
"type": {"type: map", "items": "string"},
"default": {}
}],
"my-property" : {
"key" : 3
Expand Down
2 changes: 1 addition & 1 deletion share/idl_grammar/org/apache/avro/idl/Idl.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 5a401f2

Please sign in to comment.