apple / app-store-server-library-python

MIT License
146 stars 31 forks source link

Inherit enum classes with primiary types #32

Closed elonzh closed 11 months ago

elonzh commented 1 year ago

Currently, the package defines enums by inheriting enum.Enum class, this will cause TypeError when serializing it to json without a default function.

See:

alexanderjordanbaker commented 1 year ago

Hello @elonzh, could you please provide an example of this error when using the App Store Server API client?

elonzh commented 1 year ago

Here is an example:

import json
from appstoreserverlibrary.models.AutoRenewStatus import AutoRenewStatus
from enum import IntEnum

class AutoRenewStatusWithInt(IntEnum):
    """
    The renewal status for an auto-renewable subscription.

    https://developer.apple.com/documentation/appstoreserverapi/autorenewstatus
    """
    OFF = 0
    ON = 1

# OK
print(json.dumps({
    "status": AutoRenewStatusWithInt.ON
}))

# TypeError: Object of type AutoRenewStatus is not JSON serializable
print(json.dumps({
    "status": AutoRenewStatus.ON
}))