ch-robinson / dotnet-avro

An Avro implementation for .NET
https://engineering.chrobinson.com/dotnet-avro/
MIT License
135 stars 51 forks source link

Enum default values are not used when the reader encounters an unrecognized symbol #137

Closed woodlee closed 2 years ago

woodlee commented 3 years ago

Currently, if a writer adds a new symbol to an enum, but a reader using Chr.Avro does not know about it, the logic here is triggered and an exception is thrown.

Avro 1.9 added the ability to specify a default value as part of an enum's definition, but we've found that Chr.Avro doesn't seem to use it. The spec says this about enum defaults:

A default value for this enumeration, used during resolution when the reader encounters a symbol from the writer that isn't defined in the reader's schema (optional). The value provided here must be a JSON string that's a member of the symbols array. See documentation on schema resolution for how this gets used.

I suspect all that's needed is a change at the above-linked code location to check and see if a default has been specified, and if so, return it instead of throwing the UnsupportedTypeException. Just figured I'd run it by you before attempting a PR since you would of course know better if the fix for this would more appropriately go elsewhere!

dstelljes commented 3 years ago

Yeah, that’d be a good addition. Along with the code you linked, there would need to be a new Default property on EnumSchema and support for that property added to the JSON reader/writer, but that should be pretty straightforward.

PR definitely welcome, otherwise we’ll make sure to get it in 8.0.0.

dstelljes commented 2 years ago

Released with 8.0.0-pre.0.