You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var Avro = require('avsc');
var schema = Avro.parse('./example.avsc');
var data = {values: ["test"]}
schema.toBuffer(data);
TypeError: Object.keys called on non-object
at Function.keys (native)
at UnionType._write (avsc/lib/types.js:826:19)
at ArrayType._write (avsc/lib/types.js:1367:19)
at RecordType.writeExample [as _write] (eval at <anonymous> (avsc/lib/types.js:1678:10), <anonymous>:3:6)
at RecordType.Type.toBuffer (avsc/lib/types.js:264:8)
Interestingly enough, this succeeds when passing in an empty array for values.
I've tested the same schema with the official python avro implementation to confirm that my schema is valid. Please let me know if there is any more information that I should provide!
The text was updated successfully, but these errors were encountered:
Hey! This is related to how decoded unions are represented. The default UnionType expects its values to be wrapped inside objects (similarly to their JSON representation). So for your example, the value ({values: ['test']}) you are passing should be transformed to {values: [{'string': 'test'}]}.
This is required to correctly serialize all union values. Here's an example of an ambiguous case otherwise:
vartype=avro.parse(['int','float']);varbuf=type.toBuffer(2);// Should 2 be serialized as an integer or a float?
The python implementation can cause corruption (and also requires a linear scan of branches during serialization, which is slow). If you're curious, you can take a look at #16 for more context.
Not all unions lead to ambiguous cases though so I'm actually working on adding an option to represent decoded union values without the wrapping object when possible.
Hi there! I've hit an issue where encoding an ArrayType that has a UnionType for its items fails.
Here's the example running this
Interestingly enough, this succeeds when passing in an empty array for values.
I've tested the same schema with the official python avro implementation to confirm that my schema is valid. Please let me know if there is any more information that I should provide!
The text was updated successfully, but these errors were encountered: