Skip to content

to_dict generates non serializable object because of enums #93

Description

@farfanoide

using Xero-python 1.8 on python 3.10.4 trying to convert a Journal to dictionary using to_dict method.

I expect to have a json serializable dict of primitive values however I get an AccountType enum which is not serializable.
simple enough to have a custom encoder that handles enums but it would also be rather simple to extend the serializer process here to enable proper conversion.

adding following code to models.py fixes the issue:

from enum import Enum
@serialize_to_dict.register(Enum)
def serialize_enum_to_dict(value):
    return value.value

please let me know if a pr is welcome for this or if further information is required.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions