Open kitschen opened 4 years ago
I'd happily include this as an enum_name_serializer
/deserializer
utility function (indeed, I have some suspiciously similar code in my personal projects), but I'm against including it by default in JSONSerializer
as it's not a canonical serialization.
You could equally well serialize an Enum
by its value
, or even its index in definition order.
I rewrote this same feature and came to submit a PR only to find @kitschen already suggested it. A supported utility function would be great.
Would be nice to have this included by default. I'd vote for serialising the value rather than the name, as it allows you to refactor without breaking existing serialised files.
You can add a generic serializer which works for all Enums like so
Maybe add this to default JSONSerializer or point to it in the docs?
Example test: