Skip to content

Enumerator JSON serialization broken when using enumerated classes #185

@madsmtm

Description

@madsmtm

Title mostly speaks for itself, the JSON serializer can't handle enum.Enum types, which you (can) use in sqlalchemy.types.Enum

Example code is here

Traceback:
  ...
  File "[VENV]\site-packages\eve\methods\get.py", line 220, in _perform_find
    build_response_document(document, resource, embedded_fields)
  File "[VENV]\site-packages\eve\methods\common.py", line 623, in build_response_document
    document[config.ETAG] = document_etag(document, ignore_fields=ignore_fields)
  File "[VENV]\site-packages\eve\utils.py", line 363, in document_etag
    dumps(value_, sort_keys=True, default=json_encoder.default).encode("utf-8")
  File "[VENV]\site-packages\bson\json_util.py", line 408, in dumps
    return json.dumps(_json_convert(obj, json_options), *args, **kwargs)
  File "[VENV]\json\__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "[VENV]\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "[VENV]\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "[VENV]\site-packages\eve\io\base.py", line 37, in default
    return json.JSONEncoder.default(self, obj)
  File "[VENV]\site-packages\simplejson\encoder.py", line 273, in default
    o.__class__.__name__)
TypeError: Object of type ABEnum is not JSON serializable

Might be related to #183

Setup:

  • Version: 0.7.0
  • OS: Windows 10
  • Python Version: 3.6

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions