xero-python
xero-python copied to clipboard
to_dict generates non serializable object because of enums
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.
bumping this issue as I'm having the same problem.
Enum issue was solved for me by upgrading to xero-python==1.16.0 however note that this introduced different errors for UUID and None
from xero_python.api_client.serializer import serialize_model
@serialize_model.register(UUID)
def serialize_uuid_model(model):
"""Serializes api model into an json serializable object.
:param model: BaseModel instance to serialize
:return: serialized object
"""
return model.hex