-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
union type error #20
Comments
The error is expected, this record isn't valid (see below). The error message isn't explicit, but this is a purposeful trade-off (encoding is designed to be as fast as possible; you can always use Your record is invalid because unions are by default deserialized to objects with single key the type of the chosen branch (similar to their JSON representation). This isn't ideal but the best way to handle all unions properly in JavaScript. You can take a look here for more information and even a way to implement the behavior you initially expected. TL;DR: Your record should have looked like:
|
just to understand the trade off you mention:
so either i tell my client to change the way they generate the json or i find myself another library? |
Right.
It depends what you mean. It's valid JSON but it isn't a valid JSON encoding of a record according to your schema (see Avro's JSON encoding specification). For example,
No. See above. Finally, even if the data is generated out of your control, in this case you can still conveniently convert it into valid records by using Hope this makes sense. |
make sense and clone method with wrapUnions did the trick preprocessing the json to convert to something acceptable for the parser. |
Is it intended that clone's, var schema = {
type: 'record',
name: 'test',
fields: [
{ name: 'test', type: ['null', 'string'], default: null },
{ name: 'foo', type: ['null', 'string'], default: null }
]
};
var testType = avsc.parse(schema);
var incomplete = {foo: {string: 'bar'} }
var complete = {foo: {string: 'bar'}, test: null }
// Works as expected
testType.clone(complete, { wrapUnions: true });
// Throws error: invalid ["null","string"]: undefined
testType.clone(incomplete, { wrapUnions: true }); |
@edulop91 - It should, I'll add this. |
@mtth Awesome! Thanks for the quick response! |
@mtth @tboothman @asarubbi @edulop91 is it solved ? invalid union index: 4032 [object Object]" |
given this AVSC:
and this JSON:
and using permutations between
country
in the JSONcountry
in the AVSC** Parsing Error **
my code:
The text was updated successfully, but these errors were encountered: