Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
1.10.0
-
None
-
None
Description
I apologize in advance if this is a misunderstanding of funcitonality on my part and I have only tested it on the latest published npm package (https://www.npmjs.com/package/avro-js) but if not this should be a rather serious bug.
According to multiple sources (https://avro.apache.org/docs/1.8.1/spec.htm), nullable values should be specified as a unon with the type null, e.g. for string "['null', 'string']"
However, given the following code (that from what I understand should be valid)
var type = avro.parse({ name: 'Pet', type: 'record', fields: [ { name: 'name', type: ['null', 'string'] } ] }); var pet = { name: "Fido" }; var buf = type.toBuffer(pet); var obj = type.fromBuffer(buf); console.log(obj);
I get the followin error on "type.toBuffer(pet)"
Error: invalid ["null","string"]: "Fido"
Curiously, if I instead set pet name as "null" instead of "Fido" everything runs fine and returns a correct output given the input. Though this is not very useful as the field still can not be changed to anything else beside null.
... var pet = { name: null }; ... console.log(obj);
Pet { name: null }
Expected behavior is that both string and null should be valid parameters without throwing an exception.