klarna / erlavro

Avro support for Erlang/Elixir (http://avro.apache.org/)
Apache License 2.0
131 stars 39 forks source link

Options to decode keys as atoms #95

Open davydog187 opened 4 years ago

davydog187 commented 4 years ago

I was looking to decode keys to atoms as an option in https://github.com/cogini/avro_schema/commit/2c07ca2fafde949fa78ec9f0af85245a92c6b731 and https://github.com/cogini/avro_schema/issues/25

However, as far as I can reason through the erlavro decoder hook code, I don't think it is possible to implement this as a decoder hook. In this case, it might make more sense to implement this feature directly into erlavro, and provide options similar to the Jason.decode/2 function.

I am happy to implement, but I would appreciate feedback if I'm wasting my time and this is easily implemented as a decoder hook. Thanks!

zmstone commented 4 years ago

I'd say go ahead add a new decoder option.

For records and enums, ideally it should be atom() in schema, i.e. ensure atom() at schema's 'compile' time. in this case, we do not need to convert binary() to atom() over and over again. But this is likely a big change and may break backward compatibility.