[issue18264] enum.IntEnum is not compatible with JSON serialisation

Barry A. Warsaw report at bugs.python.org
Wed Jun 19 15:58:04 CEST 2013


Barry A. Warsaw added the comment:

On Jun 19, 2013, at 01:45 PM, Nick Coghlan wrote:

>Allowing __str__ to be inherited from Enum rather than from the concrete type
>will similarly break any serialisation protocol that relies on str() to
>handle integers. The float case is even trickier, since failing to inherit
>__repr__ would rather miss the point of the whole exercise...

Serialization isn't the only issue - you have to know how to deserialize as
well.  I use JSON extensively in Mailman's REST API.  For enums I always
encode them to just the member name, because I always know what enum class
will be used to deserialize them.

(TBH, I wish the json module had better hooks for extending both serialization
and deserialization of non-basic types.)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18264>
_______________________________________


More information about the Python-bugs-list mailing list