Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_dict generates non serializable object because of enums #93

Open
farfanoide opened this issue Jun 26, 2022 · 2 comments
Open

to_dict generates non serializable object because of enums #93

farfanoide opened this issue Jun 26, 2022 · 2 comments
Assignees

Comments

@farfanoide
Copy link

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.

@mseflek
Copy link

mseflek commented Oct 3, 2022

bumping this issue as I'm having the same problem.

@RettBehrens RettBehrens self-assigned this Oct 4, 2022
@farfanoide
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants